[FFmpeg-trac] #2658(avformat:new): Written mp4 with h264/AAC unplayable (discrepancy with libav)
FFmpeg
trac at avcodec.org
Tue Jun 11 17:13:30 CEST 2013
#2658: Written mp4 with h264/AAC unplayable (discrepancy with libav)
----------------------------------+----------------------------------
Reporter: Lastique | Type: defect
Status: new | Priority: normal
Component: avformat | Version: 1.2.1
Keywords: | Blocked By:
Blocking: | Reproduced by developer: 0
Analyzed by developer: 0 |
----------------------------------+----------------------------------
In our application, we write mp4 files through libav 9.6 using its public
API. In one particular case we mux h264 video and AAC audio into the file,
so the code is roughly like this:
{{{
AVFormatContext* m_av_format_ctx = ...;
AVCodec* video_codec = NULL;
AVCodec* audio_codec = NULL;
CodecID codec_id = AV_CODEC_ID_H264;
video_codec = avcodec_find_encoder(codec_id);
m_av_format_ctx->oformat->video_codec = codec_id;
m_av_format_ctx->video_codec_id = codec_id;
AVStream* av_stream = avformat_new_stream(m_av_format_ctx, NULL);
av_stream->id = 0;
av_stream->r_frame_rate = av_d2q(m_video_info->fps, std::numeric_limits<
unsigned short >::max());
av_stream->time_base.num = av_stream->r_frame_rate.den;
av_stream->time_base.den = av_stream->r_frame_rate.num;
av_video_codec_ctx = av_stream->codec;
// av_stream->codec initialization skipped...
av_video_codec_ctx->codec_type = AVMEDIA_TYPE_VIDEO;
av_video_codec_ctx->flags |= CODEC_FLAG_GLOBAL_HEADER;
av_video_codec_ctx->time_base = { 1, 1000 };
codec_id = AV_CODEC_ID_AAC;
audio_codec = avcodec_find_encoder(codec_id);
m_av_format_ctx->oformat->audio_codec = codec_id;
m_av_format_ctx->audio_codec_id = codec_id;
AVStream* av_stream = avformat_new_stream(m_av_format_ctx, NULL);
av_stream->id = 1;
av_audio_codec_ctx = av_stream->codec;
av_stream->time_base.num = 1;
av_stream->time_base.den = m_audio_info->sample_rate;
av_audio_codec_ctx->codec_type = AVMEDIA_TYPE_AUDIO;
av_audio_codec_ctx->flags |= CODEC_FLAG_GLOBAL_HEADER;
av_audio_codec_ctx->time_base = { 1, 1000 };
}}}
(Sorry, I cannot post the complete code)
Our internal video and audio timestamps are in milliseconds, but for audio
we convert them to the sample rate-based values by calling
av_rescale_rnd(). Video timestamps are converted to frame number (since
for fixed-fps media we must specify time_base as 1/fps).
The files are written ok by libav 9.6 this way, but not by ffmpeg 1.2.1
(our code is unchanged). Files written by ffmpeg are not playable, video
frame rate is extremely low (about 1 frame per several seconds). I have
attached files written by libav and ffmpeg.
--
Ticket URL: <https://ffmpeg.org/trac/ffmpeg/ticket/2658>
FFmpeg <http://ffmpeg.org>
FFmpeg issue tracker
More information about the FFmpeg-trac
mailing list