You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.9KB

  1. /*
  2. * MPEG4 Video frame extraction
  3. * Copyright (c) 2003 Fabrice Bellard.
  4. * Copyright (c) 2003 Michael Niedermayer.
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include "parser.h"
  23. #include "mpegvideo.h"
  24. /* XXX: make it use less memory */
  25. static int av_mpeg4_decode_header(AVCodecParserContext *s1,
  26. AVCodecContext *avctx,
  27. const uint8_t *buf, int buf_size)
  28. {
  29. ParseContext1 *pc = s1->priv_data;
  30. MpegEncContext *s = pc->enc;
  31. GetBitContext gb1, *gb = &gb1;
  32. int ret;
  33. s->avctx = avctx;
  34. s->current_picture_ptr = &s->current_picture;
  35. if (avctx->extradata_size && pc->first_picture){
  36. init_get_bits(gb, avctx->extradata, avctx->extradata_size*8);
  37. ret = ff_mpeg4_decode_picture_header(s, gb);
  38. }
  39. init_get_bits(gb, buf, 8 * buf_size);
  40. ret = ff_mpeg4_decode_picture_header(s, gb);
  41. if (s->width) {
  42. avcodec_set_dimensions(avctx, s->width, s->height);
  43. }
  44. s1->pict_type= s->pict_type;
  45. pc->first_picture = 0;
  46. return ret;
  47. }
  48. static int mpeg4video_parse_init(AVCodecParserContext *s)
  49. {
  50. ParseContext1 *pc = s->priv_data;
  51. pc->enc = av_mallocz(sizeof(MpegEncContext));
  52. if (!pc->enc)
  53. return -1;
  54. pc->first_picture = 1;
  55. return 0;
  56. }
  57. static int mpeg4video_parse(AVCodecParserContext *s,
  58. AVCodecContext *avctx,
  59. uint8_t **poutbuf, int *poutbuf_size,
  60. const uint8_t *buf, int buf_size)
  61. {
  62. ParseContext *pc = s->priv_data;
  63. int next;
  64. if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
  65. next= buf_size;
  66. }else{
  67. next= ff_mpeg4_find_frame_end(pc, buf, buf_size);
  68. if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
  69. *poutbuf = NULL;
  70. *poutbuf_size = 0;
  71. return buf_size;
  72. }
  73. }
  74. av_mpeg4_decode_header(s, avctx, buf, buf_size);
  75. *poutbuf = (uint8_t *)buf;
  76. *poutbuf_size = buf_size;
  77. return next;
  78. }
  79. AVCodecParser mpeg4video_parser = {
  80. { CODEC_ID_MPEG4 },
  81. sizeof(ParseContext1),
  82. mpeg4video_parse_init,
  83. mpeg4video_parse,
  84. ff_parse1_close,
  85. ff_mpeg4video_split,
  86. };