[FFmpeg-devel] Patch for output_example.c

Steve Allen steve.allen
Thu Dec 18 10:44:00 CET 2008


Hi,

The example output code works fine with the MPEG4 codec but fails with the H264 codec.  The reason for H264's difficulties lie in the "ff_avc_parse_nal_units" routine which reassigns the packet buffer following the conversion from stream to file format NAL codes. The reassignment then breaks the video_outbuf in the output_example.c code.

My suggested solution is to place an av_dup_packet() and av_free_packet() call around the av_write_frame() routine so that only the temporary pkt gets reassigned and no the video_outbuf.

The problem can be seen by generating a ".mp4" file and forcing the codec to be H264 (rather than the defaut MPEG4)

    /* allocate the output media context */
    oc = av_alloc_format_context();
    if (!oc) {
        fprintf(stderr, "Memory error\n");
        exit(1);
    }

    // Force video codec
    fmt->video_codec = CODEC_ID_H264;


Kind regards,

Steve


--- ffmpeg.orig\output_example.c          2008-12-18 09:22:39.470000000 +0000
+++ ffmpeg\output_example.c 2008-12-18 09:33:55.296000000 +0000
@@ -388,9 +388,11 @@
             pkt.stream_index= st->index;
             pkt.data= video_outbuf;
             pkt.size= out_size;
+            av_dup_packet(&pkt);    // Added SRA

             /* write the compressed frame in the media file */
             ret = av_write_frame(oc, &pkt);
+            av_free_packet(&pkt);   // Added SRA
         } else {
             ret = 0;
         }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ffmpeg.diff
Type: application/octet-stream
Size: 539 bytes
Desc: ffmpeg.diff
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20081218/9458b0fc/attachment.obj>



More information about the ffmpeg-devel mailing list