You need to manipulate the pts of the packet after encoding and before writing to the file... Its not unusual to have the time_base of the stream changed by ffmpeg. Check line 869 of the ffmpeg.c source code at https://www.ffmpeg.org/doxygen/trunk/ffmpeg_8c-source.html
2015-04-24 13:33 GMT-03:00 cesar pachon <[email protected]>: > I am muxing video using ffmpeg 2.1.3 with libavcodec 55.39.101 (forced to > that version because is the one available in google-chrome PNACL port > project). all my frames seems to have bad the time. they try to be rendered > all at once at the beggining of the video when playing it. > > I am setting the stream time base to 1/25, but just after calling > avformat_write_header, it has the value of -18082736/1. in each frame, when > I print the stream time_base it says 1/12800, while the time_base of codec > is always ok (1/25). > > console log before and after av_format_write_header: > > before avformat_write_header stream time_base: 1/25 > after avformat_write_header ret 0 stream time_base: -18082736/1 > > the code (abreviated to keep the post short, all calls in the original > version had error checking): > > AVCodecContext *codecContext; > AVCodec * codec = avcodec_find_encoder(codec_id); > myOutputStream->stream = avformat_new_stream(outputFormatContext, *codec); > myOutputStream->stream->id = outputFormatContext->nb_streams-1; > codecContext = myOutputStream->stream->codec; > codecContext->codec_id = codec_id; > codecContext->bit_rate = 400000; > codecContext->width = width; > codecContext->height = height; > myOutputStream->stream->time_base = (AVRational){ 1, 25 }; > codecContext->time_base = myOutputStream->stream->time_base; > codecContext->gop_size = 12; > codecContext->pix_fmt = AV_PIX_FMT_YUV420P; > AVDictionary *opt = NULL; > av_dict_copy(&opt, opt_arg, 0); > ret = avcodec_open2(codecContext, codec, &opt); > av_dict_free(&opt); > myOutputStream->frame = alloc_picture(codecContext->pix_fmt, > codecContext->width, codecContext->height); > myOutputStream->tmp_frame = alloc_picture(AV_PIX_FMT_YUV420P, > codecContext->width, codecContext->height); > > //before: printing g_outputContext->stream time_base here > ret = avformat_write_header(g_outputContext, &opt); > //after: printing g_outputContext->stream time_base here > > > (note: I also posted this question in stackoverflow: > http://stackoverflow.com/questions/29850246/ffmpeg-avformat-write-header-changing-my-stream-time-base > ) > > > Cesar Pachón > ------------------------------------------------------------- > www.cesarpachon.com, just a digital hermit > > > _______________________________________________ > Libav-user mailing list > [email protected] > http://ffmpeg.org/mailman/listinfo/libav-user > > -- ----------------------------------------------------------------- Rafael Lúcio
_______________________________________________ Libav-user mailing list [email protected] http://ffmpeg.org/mailman/listinfo/libav-user
