[haiku-commits] haiku: hrev52169 - src/add-ons/media/plugins/ffmpeg

  • From: Barrett17 <b.vitruvio@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 5 Aug 2018 07:37:27 -0400 (EDT)

hrev52169 adds 5 changesets to branch 'master'
old head: b5d0ce85f454ed6f0dd64f6eb77302ac26dc5c4c
new head: 201707aee88fd6332761a740d26d866bf0cde761
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=201707aee88f+%5Eb5d0ce85f454

----------------------------------------------------------------------------

a72bbd5bd245: AVFormatWriter: Cleanup GET_CONTEXT_DEFAULTS macro
  
  * av_get_context_default(1,2,3) are deprecated. The functions are supposed
  to "reset" a codec context to a clean state so that it can be opened again.
  It was used to allow using AVStream.codec as a decoding context
  That behaviour is now deprecated, so that's why the function is too.
  * hint: The code is probably still doing something bad in that regard.
  * Unfortunately the macro removal did end up in the codecparam diff,
  but was originally intended to be a commit alone I can't rewrite history
  unfortunately, at least an explanation is given here. In any case the
  code wasn't used so no functional change, this is mostly educated cleanup.

e93fce62f2ed: AVFormatWriter: Correctly set DTS
  
  * Fixes timestamp warning from ffmpeg.
  * Fixes #13407 AFAICT. But please test.

bbe2746941c4: AVFormatWriter: Fix debug build

5e2290b0830c: AVFormatWriter: Set packet stream index to current

201707aee88f: AVCodecEncoder: Skip frames
  
  * Fix garbage put into videos while encoding.
  * Testing welcome.
  * Various fixes are still waiting to be merged into Haiku.
  * Fixes sponsored by the V\OS project.

                                        [ Barrett17 <b.vitruvio@xxxxxxxxx> ]

----------------------------------------------------------------------------

2 files changed, 18 insertions(+), 17 deletions(-)
.../media/plugins/ffmpeg/AVCodecEncoder.cpp      | 26 ++++++++++----------
.../media/plugins/ffmpeg/AVFormatWriter.cpp      |  9 ++++---

############################################################################

Commit:      a72bbd5bd2453acc0139bd9c4394806f0f2b2278
URL:         https://git.haiku-os.org/haiku/commit/?id=a72bbd5bd245
Author:      Barrett17 <b.vitruvio@xxxxxxxxx>
Date:        Sun Aug  5 09:31:40 2018 UTC

AVFormatWriter: Cleanup GET_CONTEXT_DEFAULTS macro

* av_get_context_default(1,2,3) are deprecated. The functions are supposed
to "reset" a codec context to a clean state so that it can be opened again.
It was used to allow using AVStream.codec as a decoding context
That behaviour is now deprecated, so that's why the function is too.
* hint: The code is probably still doing something bad in that regard.
* Unfortunately the macro removal did end up in the codecparam diff,
but was originally intended to be a commit alone I can't rewrite history
unfortunately, at least an explanation is given here. In any case the
code wasn't used so no functional change, this is mostly educated cleanup.

----------------------------------------------------------------------------

diff --git a/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp 
b/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp
index 8e2d9a9e22..cce3d67d17 100644
--- a/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp
+++ b/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp
@@ -48,8 +48,6 @@ static const size_t kIOBufferSize = 64 * 1024;
        // TODO: This could depend on the BMediaFile creation flags, IIRC,
        // they allow to specify a buffering mode.
 
-#define GET_CONTEXT_DEFAULTS 0
-
 typedef AVCodecID CodecID;
 
 // #pragma mark - AVFormatWriter::StreamCookie

############################################################################

Commit:      e93fce62f2ed4935930c236fa708a99af54384c4
URL:         https://git.haiku-os.org/haiku/commit/?id=e93fce62f2ed
Author:      Barrett17 <b.vitruvio@xxxxxxxxx>
Date:        Sun Aug  5 09:43:59 2018 UTC

Ticket:      https://dev.haiku-os.org/ticket/13407

AVFormatWriter: Correctly set DTS

* Fixes timestamp warning from ffmpeg.
* Fixes #13407 AFAICT. But please test.

----------------------------------------------------------------------------

diff --git a/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp 
b/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp
index cce3d67d17..554aa95bc1 100644
--- a/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp
+++ b/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp
@@ -308,6 +308,8 @@ AVFormatWriter::StreamCookie::WriteChunk(const void* 
chunkBuffer,
                * fStream->time_base.den / (1000000.0 * fStream->time_base.num)
                + 0.5);
 
+       fPacket.dts = fPacket.pts;
+
        fPacket.flags = 0;
        if ((encodeInfo->flags & B_MEDIA_KEY_FRAME) != 0)
                fPacket.flags |= AV_PKT_FLAG_KEY;

############################################################################

Commit:      bbe2746941c4c88bea2a0b1da3a38cdcb33984c9
URL:         https://git.haiku-os.org/haiku/commit/?id=bbe2746941c4
Author:      Barrett17 <b.vitruvio@xxxxxxxxx>
Date:        Sun Aug  5 09:53:43 2018 UTC

AVFormatWriter: Fix debug build

----------------------------------------------------------------------------

diff --git a/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp 
b/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp
index 554aa95bc1..56c7268287 100644
--- a/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp
+++ b/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp
@@ -268,7 +268,7 @@ AVFormatWriter::StreamCookie::Init(media_format* format,
 
        TRACE("  stream->time_base: (%d/%d), codec->time_base: (%d/%d))\n",
                fStream->time_base.num, fStream->time_base.den,
-               fStream->codecpar->time_base.num, 
fStream->codecpar->time_base.den);
+               fStream->code->time_base.num, fStream->codec->time_base.den);
 
 #if 0
        // Write the AVCodecContext pointer to the user data section of the
@@ -317,7 +317,7 @@ AVFormatWriter::StreamCookie::WriteChunk(const void* 
chunkBuffer,
        TRACE_PACKET("  PTS: %lld (stream->time_base: (%d/%d), "
                "codec->time_base: (%d/%d))\n", fPacket.pts,
                fStream->time_base.num, fStream->time_base.den,
-               fStream->codecpar->time_base.num, 
fStream->codecpar->time_base.den);
+               fStream->codec->time_base.num, fStream->codec->time_base.den);
 
 #if 0
        // TODO: Eventually, we need to write interleaved packets, but

############################################################################

Commit:      5e2290b0830c8457d1481c31b7bcd8d4b708ab7e
URL:         https://git.haiku-os.org/haiku/commit/?id=5e2290b0830c
Author:      Barrett17 <b.vitruvio@xxxxxxxxx>
Date:        Sun Aug  5 11:23:45 2018 UTC

AVFormatWriter: Set packet stream index to current

----------------------------------------------------------------------------

diff --git a/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp 
b/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp
index 56c7268287..4a20b5a9a1 100644
--- a/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp
+++ b/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp
@@ -303,6 +303,7 @@ AVFormatWriter::StreamCookie::WriteChunk(const void* 
chunkBuffer,
 
        fPacket.data = const_cast<uint8_t*>((const uint8_t*)chunkBuffer);
        fPacket.size = chunkSize;
+       fPacket.stream_index = fStream->index;
 
        fPacket.pts = int64_t((double)encodeInfo->start_time
                * fStream->time_base.den / (1000000.0 * fStream->time_base.num)

############################################################################

Revision:    hrev52169
Commit:      201707aee88fd6332761a740d26d866bf0cde761
URL:         https://git.haiku-os.org/haiku/commit/?id=201707aee88f
Author:      Barrett17 <b.vitruvio@xxxxxxxxx>
Date:        Sun Aug  5 11:24:34 2018 UTC

AVCodecEncoder: Skip frames

* Fix garbage put into videos while encoding.
* Testing welcome.
* Various fixes are still waiting to be merged into Haiku.
* Fixes sponsored by the V\OS project.

----------------------------------------------------------------------------

diff --git a/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.cpp 
b/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.cpp
index c55006193d..c11bf39ff2 100644
--- a/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.cpp
+++ b/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.cpp
@@ -723,28 +723,28 @@ AVCodecEncoder::_EncodeVideo(const void* buffer, int64 
frameCount,
                                fCodecContext->time_base.num, 
fCodecContext->time_base.den);
                }
 
-               // Setup media_encode_info, most important is the time stamp.
-               info->start_time = (bigtime_t)(fFramesWritten * 1000000LL
-                       / fInputFormat.u.raw_video.field_rate);
+               if (gotPacket == 1) {
+                       // Setup media_encode_info, most important is the time 
stamp.
+                       info->start_time = (bigtime_t)(fFramesWritten * 
1000000LL
+                               / fInputFormat.u.raw_video.field_rate);
 
-               info->flags = 0;
-               if (fCodecContext->coded_frame->key_frame)
-                       info->flags |= B_MEDIA_KEY_FRAME;
+                       info->flags = 0;
+                       if (fCodecContext->coded_frame->key_frame)
+                               info->flags |= B_MEDIA_KEY_FRAME;
 
-               // Write the chunk
-               ret = WriteChunk(pkt.data, pkt.size, info);
-               if (ret != B_OK) {
-                       TRACE("  error writing chunk: %s\n", strerror(ret));
-                       break;
+                       // Write the chunk
+                       ret = WriteChunk(pkt.data, pkt.size, info);
+                       if (ret != B_OK) {
+                               TRACE("  error writing chunk: %s\n", 
strerror(ret));
+                               break;
+                       }
                }
-
                // Skip to the next frame (but usually, there is only one to 
encode
                // for video).
                frameCount--;
                fFramesWritten++;
                buffer = (const void*)((const uint8*)buffer + bufferSize);
        }
-
        return ret;
 }
 


Other related posts: