Skip to content

Commit

Permalink
[muxer] Populate codecpar, silence lavc deprecated warning
Browse files Browse the repository at this point in the history
  • Loading branch information
eumagga0x2a committed Apr 3, 2017
1 parent 098e81a commit d2b1f44
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 57 deletions.
105 changes: 55 additions & 50 deletions avidemux_core/ADM_coreMuxer/src/ADM_coreMuxerFfmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ extern "C" {
\fn ffmpuxerSetExtradata
\brief dupe the extradata if needed
*/
bool ffmpuxerSetExtradata(AVCodecContext *context, int size, const uint8_t *data)
bool ffmpuxerSetExtradata(AVCodecParameters *params, int size, const uint8_t *data)
{
if(!size)
{
context->extradata=NULL;
context->extradata_size=0;
params->extradata=NULL;
params->extradata_size=0;
return true;
}
uint8_t *copy=(uint8_t *)av_malloc( (1+(size>>4))<<4);;
memcpy(copy,data,size);
context->extradata=copy;
context->extradata_size=size;
params->extradata=copy;
params->extradata_size=size;
return true;
}

Expand Down Expand Up @@ -159,31 +159,34 @@ bool muxerFFmpeg::initVideo(ADM_videoStream *stream)
printf("[FF] new stream failed\n");
return false;
}
AVCodecContext *c;
c = video_st->codec;
c->sample_aspect_ratio.num=1;
c->sample_aspect_ratio.den=1;
video_st->sample_aspect_ratio=c->sample_aspect_ratio;
AVCodecParameters *par;
par = video_st->codecpar;
par->sample_aspect_ratio.num=1;
par->sample_aspect_ratio.den=1;
video_st->sample_aspect_ratio=par->sample_aspect_ratio;
par->bit_rate=9000*1000;
par->codec_type = AVMEDIA_TYPE_VIDEO;
par->width = stream->getWidth();
par->height =stream->getHeight();

uint32_t videoExtraDataSize=0;
uint8_t *videoExtraData;
stream->getExtraData(&videoExtraDataSize,&videoExtraData);
printf("[FF] Using %d bytes for video extradata\n",(int)videoExtraDataSize);
ffmpuxerSetExtradata(c,videoExtraDataSize,videoExtraData);
ffmpuxerSetExtradata(par,videoExtraDataSize,videoExtraData);

AVCodecContext *c;
c = video_st->codec;
c->rc_buffer_size=8*1024*224;
c->rc_max_rate=9500*1000;
c->rc_min_rate=0;
c->bit_rate=9000*1000;
c->codec_type = AVMEDIA_TYPE_VIDEO;
c->flags=CODEC_FLAG_QSCALE;
c->width = stream->getWidth();
c->height =stream->getHeight();

uint32_t fcc=stream->getFCC();

if(isMpeg4Compatible(fcc))
{
c->codec_id = AV_CODEC_ID_MPEG4;
par->codec_id = AV_CODEC_ID_MPEG4;
if(stream->providePts()==true)
{
c->has_b_frames=1; // in doubt...
Expand All @@ -210,28 +213,28 @@ bool muxerFFmpeg::initVideo(ADM_videoStream *stream)
}

if(isH265Compatible(fcc)) {
c->codec_id = AV_CODEC_ID_HEVC;
par->codec_id = AV_CODEC_ID_HEVC;
setAvCodec(c,AV_CODEC_ID_HEVC);
} else {
c->codec_id = AV_CODEC_ID_H264;
par->codec_id = AV_CODEC_ID_H264;
setAvCodec(c,AV_CODEC_ID_H264);
}
}
else
{
if(isDVCompatible(fcc))
{
c->codec_id = AV_CODEC_ID_DVVIDEO;
par->codec_id = AV_CODEC_ID_DVVIDEO;
}else
{
if(fourCC::check(fcc,(uint8_t *)"H263"))
{
c->codec_id= AV_CODEC_ID_H263;
par->codec_id= AV_CODEC_ID_H263;
}else

if(isVP6Compatible(stream->getFCC()))
{
c->codec_id= AV_CODEC_ID_VP6F;
par->codec_id= AV_CODEC_ID_VP6F;
setAvCodec(c,AV_CODEC_ID_VP6F);
c->has_b_frames=0; // No PTS=cannot handle CTS...
c->max_b_frames=0;
Expand All @@ -240,7 +243,7 @@ bool muxerFFmpeg::initVideo(ADM_videoStream *stream)
{
c->has_b_frames=0; // No PTS=cannot handle CTS...
c->max_b_frames=0;
c->codec_id= AV_CODEC_ID_FLV1;
par->codec_id= AV_CODEC_ID_FLV1;
setAvCodec(c,AV_CODEC_ID_FLV1);

}else
Expand All @@ -249,13 +252,13 @@ bool muxerFFmpeg::initVideo(ADM_videoStream *stream)
{
c->has_b_frames=1; // No PTS=cannot handle CTS...
c->max_b_frames=2;
c->codec_id= AV_CODEC_ID_MPEG1VIDEO;
par->codec_id= AV_CODEC_ID_MPEG1VIDEO;
}
else if(fourCC::check(stream->getFCC(),(uint8_t *)"MPEG2"))
{
c->has_b_frames=1; // No PTS=cannot handle CTS...
c->max_b_frames=2;
c->codec_id= AV_CODEC_ID_MPEG2VIDEO;
par->codec_id= AV_CODEC_ID_MPEG2VIDEO;
}else
{
uint32_t id=stream->getFCC();
Expand All @@ -266,7 +269,7 @@ bool muxerFFmpeg::initVideo(ADM_videoStream *stream)
printf("[FF] Unknown video codec\n");
return false;
}
c->codec_id=cid;
par->codec_id=cid;
}
}
}
Expand Down Expand Up @@ -315,56 +318,58 @@ bool muxerFFmpeg::initAudio(uint32_t nbAudioTrack,ADM_audioStream **audio)
}
WAVHeader *audioheader=audio[i]->getInfo();;
AVCodecContext *c;
AVCodecParameters *par;
c = audio_st[i]->codec;
c->frame_size=1024; //For AAC mainly, sample per frame
par = audio_st[i]->codecpar;
par->frame_size=1024; //For AAC mainly, sample per frame
printf("[FF] Bitrate %u\n",(audioheader->byterate*8)/1000);
c->sample_rate = audioheader->frequency;
par->sample_rate = audioheader->frequency;
switch(audioheader->encoding)
{
case WAV_OGG_VORBIS:
c->codec_id = AV_CODEC_ID_VORBIS;c->frame_size=6*256;
ffmpuxerSetExtradata(c,audioextraSize,audioextraData);
par->codec_id = AV_CODEC_ID_VORBIS;par->frame_size=6*256;
ffmpuxerSetExtradata(par,audioextraSize,audioextraData);
break;
case WAV_FLAC:
c->codec_id = AV_CODEC_ID_FLAC;
par->codec_id = AV_CODEC_ID_FLAC;
// Do we already have the flac header ? FFmpeg will add it..
// If we have it, skip it
if(audioextraSize>=8 && audioextraData[0]==0x66 && audioextraData[1]==0x4c &&audioextraData[2]==0x61 && audioextraData[3]==0x43 )
ffmpuxerSetExtradata(c,audioextraSize-8,audioextraData+8);
ffmpuxerSetExtradata(par,audioextraSize-8,audioextraData+8);
else
ffmpuxerSetExtradata(c,audioextraSize,audioextraData);
ffmpuxerSetExtradata(par,audioextraSize,audioextraData);
break;
case WAV_DTS: c->codec_id = AV_CODEC_ID_DTS;c->frame_size=1024;break;
case WAV_OPUS: c->codec_id = AV_CODEC_ID_OPUS;
c->frame_size=1024;
ffmpuxerSetExtradata(c,audioextraSize,audioextraData);
case WAV_DTS: par->codec_id = AV_CODEC_ID_DTS;par->frame_size=1024;break;
case WAV_OPUS: par->codec_id = AV_CODEC_ID_OPUS;
par->frame_size=1024;
ffmpuxerSetExtradata(par,audioextraSize,audioextraData);
break;
case WAV_EAC3: c->codec_id = AV_CODEC_ID_EAC3;c->frame_size=6*256;break;
case WAV_AC3: c->codec_id = AV_CODEC_ID_AC3;c->frame_size=6*256;break;
case WAV_MP2: c->codec_id = AV_CODEC_ID_MP2;c->frame_size=1152;break;
case WAV_EAC3: par->codec_id = AV_CODEC_ID_EAC3;par->frame_size=6*256;break;
case WAV_AC3: par->codec_id = AV_CODEC_ID_AC3;par->frame_size=6*256;break;
case WAV_MP2: par->codec_id = AV_CODEC_ID_MP2;par->frame_size=1152;break;
case WAV_MP3:
// #warning FIXME : Probe deeper
c->frame_size=1152;
c->codec_id = AV_CODEC_ID_MP3;
par->frame_size=1152;
par->codec_id = AV_CODEC_ID_MP3;
break;
case WAV_PCM:
// One chunk is 10 ms (1/100 of fq)
c->frame_size=4;
c->codec_id = AV_CODEC_ID_PCM_S16LE;break;
par->frame_size=4;
par->codec_id = AV_CODEC_ID_PCM_S16LE;break;
case WAV_AAC:
ffmpuxerSetExtradata(c,audioextraSize,audioextraData);
c->codec_id = AV_CODEC_ID_AAC;
c->frame_size=1024;
ffmpuxerSetExtradata(par,audioextraSize,audioextraData);
par->codec_id = AV_CODEC_ID_AAC;
par->frame_size=1024;
break;
default:
printf("[FF]: Unsupported audio\n");
return false;
break;
}
c->codec_type = AVMEDIA_TYPE_AUDIO;
c->bit_rate = audioheader->byterate*8;
c->rc_buffer_size=(c->bit_rate/(2*8)); // 500 ms worth
c->channels = audioheader->channels;
par->codec_type = AVMEDIA_TYPE_AUDIO;
par->bit_rate = audioheader->byterate*8;
c->rc_buffer_size=(par->bit_rate/(2*8)); // 500 ms worth
par->channels = audioheader->channels;
if(useGlobalHeader()==true)
{
if(audioextraSize)
Expand Down
1 change: 1 addition & 0 deletions avidemux_plugins/ADM_muxers/muxerFlv/muxerFlv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ bool muxerFlv::open(const char *file, ADM_videoStream *s,uint32_t nbAudioTrack,A
}

AVCodecContext *c = video_st->codec;
AVCodecParameters *par = video_st->codecpar;
AVDictionary *dict = NULL;

rescaleFps(s->getAvgFps1000(),&(c->time_base));
Expand Down
6 changes: 4 additions & 2 deletions avidemux_plugins/ADM_muxers/muxerMkv/muxerMkv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ bool muxerMkv::open(const char *file, ADM_videoStream *s,uint32_t nbAudioTrack,A

AVCodecContext *c;
c = video_st->codec;
AVCodecParameters *par;
par = video_st->codecpar;
rescaleFps(s->getAvgFps1000(),&(c->time_base));
video_st->time_base=c->time_base;
c->gop_size=15;
Expand All @@ -84,8 +86,8 @@ bool muxerMkv::open(const char *file, ADM_videoStream *s,uint32_t nbAudioTrack,A
//sar=display/code
int num=1,den=1;
av_reduce(&num, &den, mkvMuxerConfig.displayWidth, s->getWidth(),65535);
c->sample_aspect_ratio.num=num;
c->sample_aspect_ratio.den=den;
par->sample_aspect_ratio.num=num;
par->sample_aspect_ratio.den=den;
video_st->sample_aspect_ratio.num=num;
video_st->sample_aspect_ratio.den=den;
ADM_info("Forcing display width of %d\n",(int)mkvMuxerConfig.displayWidth);
Expand Down
2 changes: 2 additions & 0 deletions avidemux_plugins/ADM_muxers/muxerMp4/muxerMP4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ bool muxerMP4::open(const char *file, ADM_videoStream *s,uint32_t nbAudioTrack,A
AVCodecContext *c;
AVRational myTimeBase;
c = video_st->codec;
AVCodecParameters *par;
par = video_st->codecpar;
rescaleFps(s->getAvgFps1000(),&(c->time_base));
myTimeBase=video_st->time_base=c->time_base;
ADM_info("Video stream time base :%d,%d\n",video_st->time_base.num,video_st->time_base.den);
Expand Down
6 changes: 4 additions & 2 deletions avidemux_plugins/ADM_muxers/muxerWebm/muxerWebm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ bool muxerWebm::open(const char *file, ADM_videoStream *s,uint32_t nbAudioTrack,

AVCodecContext *c;
c = video_st->codec;
AVCodecParameters *par;
par = video_st->codecpar;
rescaleFps(s->getAvgFps1000(),&(c->time_base));
video_st->time_base=c->time_base;
c->gop_size=15;
Expand All @@ -104,8 +106,8 @@ bool muxerWebm::open(const char *file, ADM_videoStream *s,uint32_t nbAudioTrack,
//sar=display/code
int num=1,den=1;
av_reduce(&num, &den, WebmMuxerConfig.displayWidth, s->getWidth(),65535);
c->sample_aspect_ratio.num=num;
c->sample_aspect_ratio.den=den;
par->sample_aspect_ratio.num=num;
par->sample_aspect_ratio.den=den;
video_st->sample_aspect_ratio.num=num;
video_st->sample_aspect_ratio.den=den;
ADM_info("Forcing display width of %d\n",(int)WebmMuxerConfig.displayWidth);
Expand Down
6 changes: 4 additions & 2 deletions avidemux_plugins/ADM_muxers/muxerffPS/muxerffPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@ const char *er;

AVCodecContext *c;
c = video_st->codec;
AVCodecParameters *par;
par = video_st->codecpar;

// Override codec settings
rescaleFps(s->getAvgFps1000(),&(c->time_base));
video_st->time_base=c->time_base;
c->bit_rate=psMuxerConfig.videoRatekBits*1000;
par->bit_rate=psMuxerConfig.videoRatekBits*1000;
c->rc_buffer_size=psMuxerConfig.bufferSizekBytes*8*1024;
c->rc_buffer_size_header=psMuxerConfig.bufferSizekBytes*8*1024;
c->gop_size=15;
Expand All @@ -105,7 +107,7 @@ const char *er;
}
for(int i=0;i<nbAudioTrack;i++)
{
audio_st[i]->codec->bit_rate=a[i]->getInfo()->byterate*8;
audio_st[i]->codecpar->bit_rate=a[i]->getInfo()->byterate*8;
}

int erx = avio_open(&(oc->pb), file, AVIO_FLAG_WRITE);
Expand Down
4 changes: 3 additions & 1 deletion avidemux_plugins/ADM_muxers/muxerffTS/muxerffTS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ bool muxerffTS::open(const char *file, ADM_videoStream *s,uint32_t nbAudioTrack,

AVCodecContext *c;
c = video_st->codec;
AVCodecParameters *par;
par = video_st->codecpar;
rescaleFps(s->getAvgFps1000(),&(c->time_base));
video_st->time_base=c->time_base;

Expand All @@ -100,7 +102,7 @@ bool muxerffTS::open(const char *file, ADM_videoStream *s,uint32_t nbAudioTrack,
}

for(int i=0;i<nbAudioTrack;i++)
audio_st[i]->codec->bit_rate=a[i]->getInfo()->byterate*8;
audio_st[i]->codecpar->bit_rate=a[i]->getInfo()->byterate*8;

int erx = avio_open(&(oc->pb), file, AVIO_FLAG_WRITE);

Expand Down

0 comments on commit d2b1f44

Please sign in to comment.