I don't know if this is right but this is how I rescale timestamps:
 //Back to yuv for encoding flattened image
                yuv_pix->av_frame=RGBtoYUV(rgb_pix->av_frame, in_stream->codec);

                avcodec_encode_video2(out_stream->codec, &styl_pkt, 
yuv_pix->av_frame, &got_something);
                if(!got_something)
                {
                    INFO(stderr, ":-( Unable to encode yuv frame.\n");
                    exit(0);
                }      
                //convert timestamps from in time_base to out time_base
                av_packet_rescale_ts(&styl_pkt, in_stream->time_base, 
out_stream->time_base);

                //log_packet(in_video_ctx->format_ctx, &orig_pkt, "Video orig. 
pkt");
                //log_packet(out_video_ctx->format_ctx, &styl_pkt, "Video styl. 
pkt");
                ret = av_write_frame(out_video_ctx->format_ctx, &styl_pkt);
                if (ret < 0)
                {
                    INFO(stderr, "Error muxing packet\n");
                    break;
                }

I'm sure I'm wrong somewhere with this timestamps management but I can't figure 
out how.
Thanks again if you can help me further!



Le 3 sept. 2015 à 18:23, Robert Krüger <[email protected]> a écrit :

> 
> 
> On Thu, Sep 3, 2015 at 5:41 PM, Talgorn François-Xavier 
> <[email protected]> wrote:
> Hi Krueger,
> 
> Thanks for your reply.
> I did check the timestamps and durations of packets.
> It appears that respectives timestamps (original/encoded) are in different 
> formats but consistent (incremental).
> I set the timebase for encoded file to the same as the original 
> (in_ctx->format_ctx is the original context).
> 
>     o_codec_ctx->time_base.num = 
> in_ctx->format_ctx->streams[in_ctx->video_stream_idx]->codec->time_base;
>     o_codec_ctx->time_base.den = 
> in_ctx->format_ctx->streams[in_ctx->video_stream_idx]->codec->time_base;
> 
> I don't know if this is OK to duplicate a timebase from H264 to be used in a 
> MP4 context.
> Since it defines the frame rate only (not the ticks/frame) it should OK I 
> guess.
> 
> no, it does not. mov/mp4 don't have a concept like frame rate.
> 
> The encoder gives you packets that have timestamps that are based on what you 
> gave the encoder as timebase. The muxer has the freedom to change that 
> timebase in avformat_write_header and if it does, the packets you get from 
> the encoder have incorrect timestamps, if you don't rescale them to the 
> timebase of the AVStream modified by the muxer. Check the example muxing.c in 
> the docs. You have to do what's done there (see line 83). If you don't, what 
> you describe (incorrect frame rate) may very well be the result. 
> _______________________________________________
> Libav-user mailing list
> [email protected]
> http://ffmpeg.org/mailman/listinfo/libav-user

_______________________________________________
Libav-user mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/libav-user

Reply via email to