[haiku-commits] r39032 - haiku/trunk/src/add-ons/media/plugins/ffmpeg

  • From: superstippi@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 20 Oct 2010 23:25:43 +0200 (CEST)

Author: stippi
Date: 2010-10-20 23:25:43 +0200 (Wed, 20 Oct 2010)
New Revision: 39032
Changeset: http://dev.haiku-os.org/changeset/39032

Modified:
   haiku/trunk/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.cpp
Log:
 * Specify length of Group of Pictures as in API example.
 * Don't hardcode PIX_FMT_YUV420P, but use the color space
   from the list of codec supported ones which has the best
   quality.
 * Maintain media_encode_info->flags by specifying whether
   a chunk contains a keyframe. According to the libavformat
   API example, all audio chunks are keyframes. For video
   chunks, use the fContext->coded_frame->key_frame flag.


Modified: haiku/trunk/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.cpp
===================================================================
--- haiku/trunk/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.cpp     
2010-10-20 21:21:43 UTC (rev 39031)
+++ haiku/trunk/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.cpp     
2010-10-20 21:25:43 UTC (rev 39032)
@@ -272,9 +272,13 @@
                // video size
                fContext->width = fInputFormat.u.raw_video.display.line_width;
                fContext->height = fInputFormat.u.raw_video.display.line_count;
-//             fContext->gop_size = 12;
+               fContext->gop_size = 12;
                // TODO: Fix pixel format or setup conversion method...
-               fContext->pix_fmt = PIX_FMT_YUV420P;
+               for (int i = 0; fCodec->pix_fmts[i] != PIX_FMT_NONE; i++) {
+                       // Use the last supported pixel format, which we hope 
is the
+                       // one with the best quality.
+                       fContext->pix_fmt = fCodec->pix_fmts[i];
+               }
 
                // TODO: Setup rate control:
 //             fContext->rate_emu = 0;
@@ -551,6 +555,7 @@
        // Setup media_encode_info, most important is the time stamp.
        info->start_time = (bigtime_t)(fFramesWritten * 1000000LL
                / fInputFormat.u.raw_audio.frame_rate);
+       info->flags = B_MEDIA_KEY_FRAME;
 
        // Write the chunk
        status_t ret = WriteChunk(fChunkBuffer, usedBytes, info);
@@ -590,13 +595,13 @@
                        fInputFormat.u.raw_video.display.line_count, 
fDstFrame.data,
                        fDstFrame.linesize);
 
-               // TODO: Look into this... avcodec.h says we need to set it.
-               fFrame->pts++;
-
                // Encode one video chunk/frame.
                int usedBytes = avcodec_encode_video(fContext, fChunkBuffer,
                        kDefaultChunkBufferSize, fFrame);
 
+               // avcodec.h says we need to set it.
+               fFrame->pts++;
+
                if (usedBytes < 0) {
                        TRACE("  avcodec_encode_video() failed: %d\n", 
usedBytes);
                        return B_ERROR;
@@ -616,6 +621,10 @@
                info->start_time = (bigtime_t)(fFramesWritten * 1000000LL
                        / fInputFormat.u.raw_video.field_rate);
 
+               info->flags = 0;
+               if (fContext->coded_frame->key_frame)
+                       info->flags |= B_MEDIA_KEY_FRAME;
+
                // Write the chunk
                ret = WriteChunk(fChunkBuffer, usedBytes, info);
                if (ret != B_OK) {


Other related posts:

  • » [haiku-commits] r39032 - haiku/trunk/src/add-ons/media/plugins/ffmpeg - superstippi