[Libav-user] Transcoding example produces incorrect FPS

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[Libav-user] Transcoding example produces incorrect FPS

Tuukka Pasanen
Hello,

I noticed that example code 'doc/examples/transcoding.c' produces in
correct FPS if it's used with MP4 container. Encoded video type doesn't
seem to be the case as I tested H264 and MPEG4 and both were nearly
identical.

With sort videos it's not much just something like 21,85 fps with 24 fps
video but longer ones can be something like 0.05 fps.

That it what ffprobe dump and when you play them they are really lagging
as they go so slow. Packets seems to be correct and it neither wise not
broken.

I don't know if this just feature or is this as bug. With ffmpeg same
source file produces correct file with correct fps.

Sincerely,

Tuukka

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

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Transcoding example produces incorrect FPS

Vassilis
Hello,

This seems like an issue I faced with my own attempt at transcoding video and a fix was suggested by a member of this mailing list (thanks James). You need to set the AVPacket duration field, otherwise this issue is present. This would mean adding something in the lines of the following line of code before your av_interleaved_write_frame is called:

// for example, if 25 FPS, and time_base is 12800, then packet.duration = 12800 / 25 = 512
output_packet.duration = format_context->streams[stream_index]->time_base.den / format_context->streams[stream_index]->time_base.num / format_context->streams[stream_index]->avg_frame_rate.num * format_context->streams[stream_index]->avg_frame_rate.den;

 /* mux encoded frame */
    ret = av_interleaved_write_frame(format_context, output_packet);

Hope this helps!
Vas

On Fri, Jul 10, 2020 at 9:19 PM Tuukka Pasanen <[hidden email]> wrote:
Hello,

I noticed that example code 'doc/examples/transcoding.c' produces in
correct FPS if it's used with MP4 container. Encoded video type doesn't
seem to be the case as I tested H264 and MPEG4 and both were nearly
identical.

With sort videos it's not much just something like 21,85 fps with 24 fps
video but longer ones can be something like 0.05 fps.

That it what ffprobe dump and when you play them they are really lagging
as they go so slow. Packets seems to be correct and it neither wise not
broken.

I don't know if this just feature or is this as bug. With ffmpeg same
source file produces correct file with correct fps.

Sincerely,

Tuukka

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

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

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

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Transcoding example produces incorrect FPS

Tuukka Pasanen

Hello,

Thanks this seems to solve problem. I didn't find this discussion with search engine. Nice explanation why number 512.

Ok I was assuming this was problem as I faced this with writing audio but when I debugged with ffmpeg.c this problem and it didn't set packet.duration and neither did transcoding.c but I assume it's been set just before writing to disk.

I update transcoding.c and try to make PR with it so nobody else shouldn't back head against wall with this.

Sincerely,

Tuukka


Vassilis kirjoitti 11.7.2020 klo 19.25:
Hello,

This seems like an issue I faced with my own attempt at transcoding video and a fix was suggested by a member of this mailing list (thanks James). You need to set the AVPacket duration field, otherwise this issue is present. This would mean adding something in the lines of the following line of code before your av_interleaved_write_frame is called:

// for example, if 25 FPS, and time_base is 12800, then packet.duration = 12800 / 25 = 512
output_packet.duration = format_context->streams[stream_index]->time_base.den / format_context->streams[stream_index]->time_base.num / format_context->streams[stream_index]->avg_frame_rate.num * format_context->streams[stream_index]->avg_frame_rate.den;

 /* mux encoded frame */
    ret = av_interleaved_write_frame(format_context, output_packet);

Hope this helps!
Vas

On Fri, Jul 10, 2020 at 9:19 PM Tuukka Pasanen <[hidden email]> wrote:
Hello,

I noticed that example code 'doc/examples/transcoding.c' produces in
correct FPS if it's used with MP4 container. Encoded video type doesn't
seem to be the case as I tested H264 and MPEG4 and both were nearly
identical.

With sort videos it's not much just something like 21,85 fps with 24 fps
video but longer ones can be something like 0.05 fps.

That it what ffprobe dump and when you play them they are really lagging
as they go so slow. Packets seems to be correct and it neither wise not
broken.

I don't know if this just feature or is this as bug. With ffmpeg same
source file produces correct file with correct fps.

Sincerely,

Tuukka

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

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

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

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

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

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".