ffmpeg - Libav Transcoding to H264: Frames being dropped -
i'm sorry if question isn't formulated, i'm getting started ffmpeg , libav. i'm not knowledgable media formats either, pretty much learned know topic past month. i've been doing much research can, , have gotten pretty far, i've gotten point i'm unsure question is! these more observations, of experts can help me out here.
i'm trying transcode gifs mp4s using ffmpeg's libraries, i'm running unusual issue when using h264 codec. in transcoding loop, maintain count of number of frames write out (by verifying homecoming value of av_write_frame). in particular sample, count total of 166 frames written out. if examine ffmpeg's converted file using ffprobe (the functionality i'm wanting emulate using program, conversion gif mp4), ffmpeg's output file seems have 166 frames, when examine output ffprobe, seem have 144 frames. find bit interesting if alter codec h264 mpeg4, output appears have 166 frames, matching ffmpeg's output , counter. similar results different gif files, counter of frames written matches ffmpeg's output's frame count, output seems drop frames.
encoder settings:
ostream_codec_context->codec_id = codec_in_use; //codec_id_h264 or codec_id_mpeg4 ostream_codec_context->pix_fmt = av_pix_fmt_yuv420p; ostream_codec_context->codec_type = avmedia_type_video; ostream_codec_context->flags = codec_flag_global_header; ostream_codec_context->profile = ff_profile_mpeg4_simple; ostream_codec_context->gop_size = istream_codec_context->gop_size; ostream_codec_context->time_base = istream_codec_context->time_base; ostream_codec_context->width = (istream_codec_context->width / 2) * 2; ostream_codec_context->height = (istream_codec_context->height / 2) * 2;
transcoding loop:
i've omitted error-checking code , debugging statements
avformat_write_header(oformat_context, null); while (av_read_frame(iformat_context, &packet) == 0 ) { if (packet.stream_index == istream_index) { avcodec_decode_video2(istream_codec_context, ipicture, &full_frame, &packet); if (full_frame) { sws_scale(image_conversion_context, (uint8_t const * const *) ipicture->data, ipicture->linesize, 0, istream_codec_context->height, opicture->data, opicture->linesize); opicture->pts = av_rescale_q(packet.pts, istream_codec_context->time_base, ostream->time_base); ret = avcodec_encode_video2(ostream_codec_context, &packet, opicture, &got_packet); if (!ret) { ret = av_write_frame(oformat_context, &packet); if (ret < 0) num_frames_written++; } } } av_free_packet(&packet); av_init_packet(&packet); }
i'm having issues output's bit-rate. can seek setting rest of encoder settings, bit-rate ffprobe shows not same give codec context. tried setting bit-rate constant values see how affected output, , although output's bit-rate isn't same give it, found input seems influence output's actual bit-rate. found post seems dealing issue, solution listed there not seem prepare issue.
http://ffmpeg.org/pipermail/libav-user/2012-july/002492.html
another thing worth mentioning various time bases don't seem match of ffmpeg's output. notably, output's tbc seems twice inverse of output codec context's time base. i'm not sure if issue gif file format, output codec context's seems set 1/100.
bit-rate calculation , setting
int calculated_br = istream_codec_context->time_base.den * avpicture_get_size(av_pix_fmt_yuv420p, ostream_codec_context->width, ostream_codec_context->height); ostream_codec_context->bit_rate = calculated_br; ostream_codec_context->rc_min_rate = calculated_br; ostream_codec_context->rc_max_rate = calculated_br; ostream_codec_context->rc_buffer_size = calculated_br;
i've got hunch these issues related me not setting pts/dts correctly, though output's pts/dts values match of ffmpeg's output.
i appreciate help, give thanks you!
using libx264 output may need manually rescale timestamps describe in this answer. explain bitrate problem.
ffmpeg h.264 libavcodec libav libavformat
No comments:
Post a Comment