Skip to content

Commit 46dbf3b

Browse files
author
Clement Champetier
committed
OutputFile: copy extradata of codec context when create a new video stream
Some codecs need / can use extradata like Huffman tables. mjpeg: Huffman tables rv10: additional flags mpeg4: global headers (they can be in the bitstream or here) ...
1 parent 5fa0d73 commit 46dbf3b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/AvTranscoder/file/OutputFile.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
#include <stdexcept>
66

7+
#ifndef FF_INPUT_BUFFER_PADDING_SIZE
8+
#define FF_INPUT_BUFFER_PADDING_SIZE 16
9+
#endif
10+
711
namespace avtranscoder
812
{
913

@@ -37,6 +41,14 @@ IOutputStream& OutputFile::addVideoStream( const VideoCodec& videoDesc )
3741
stream.codec->profile = videoDesc.getAVCodecContext().profile;
3842
stream.codec->level = videoDesc.getAVCodecContext().level;
3943

44+
// some codecs need/can use extradata to decode
45+
uint8_t* srcExtradata = videoDesc.getAVCodecContext().extradata;
46+
const int srcExtradataSize = videoDesc.getAVCodecContext().extradata_size;
47+
stream.codec->extradata = (uint8_t*) av_malloc( srcExtradataSize + FF_INPUT_BUFFER_PADDING_SIZE );
48+
memcpy( stream.codec->extradata, srcExtradata, srcExtradataSize );
49+
memset( ((uint8_t *) stream.codec->extradata) + srcExtradataSize, 0, FF_INPUT_BUFFER_PADDING_SIZE );
50+
stream.codec->extradata_size = videoDesc.getAVCodecContext().extradata_size;
51+
4052
// need to set the time_base on the AVCodecContext and the AVStream
4153
// compensating the frame rate with the ticks_per_frame and keeping
4254
// a coherent reading speed.

0 commit comments

Comments
 (0)