Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed pub_multi_track.sh frame rate #21

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Manuel-Barrabino
Copy link

@Manuel-Barrabino Manuel-Barrabino commented Dec 18, 2024

In dev/pub_multi_track.sh: The -r flag was deleted from the ffmpeg command to stream the video because it fixed the frame rate for every video output. Instead of having 3 tracks with 60, 30, and 25 fps we had all of them with 25.

⚠️ Warning - The bbb.mp4 video that is downloaded is 30fps so it would be a good idea to change it to 60fps

@Manuel-Barrabino Manuel-Barrabino changed the title fix/Fixed pub_multi_track.sh frame rate fix: Fixed pub_multi_track.sh frame rate Dec 18, 2024
@englishm
Copy link
Owner

englishm commented Dec 19, 2024

Before I merge this, @TilsonJoji, I'm wondering if this may have been intentional to try to align IDs between tracks?

@englishm
Copy link
Owner

Either way, it seems like it probably is some kind of bug to say we have different framerates, but then end up producing all the same framerate.

@englishm
Copy link
Owner

Re: starting from a 60fps source - I wouldn't mind replacing the bunny with something different if we have a reliable source... 🦾 🚀

@TilsonJoji
Copy link
Contributor

TilsonJoji commented Dec 20, 2024

Thank you for reporting the issue with constant fps for all o/p tracks @Manuel-Barrabino

Thank you @englishm for bringing this thread to my attention.

I had used -r intentionally , due to it benefits in correct frame rate interpretation and improved accuracy in time-related operations in ffmpeg should there be any issues in interpreting the input file fed to ffmpeg. The scope of this is only to specify the input frame rate to FFmpeg.

Theoretically for all the o/p streams , -r will be overridden as per the fps specified in the filter_complex.

I had a look at the reported issue

Here the problem does not lie with the usage of -r but rather lies in the position of -r in the FFmpeg CLI .

Ideal fix would be to place -r ${videofps} before the input -i "$INPUT" , i.e. on line 193 the command would look like -r ${videofps} -i "$INPUT" \ , unfortunately I misplaced it after specifying the input file.

After placing -r 25 before input , we have the expected results , output analyzed/confirmed using ffprobe ( ffmpeg out piped to ffprobe ) , as we can see in the snippet below the 3 o/p streams are set at the expected respective frame rate:

ffmpeg -hide_banner -v quiet -re -r 25 -i dev/bbb.fmp4 -filter_complex "[0:v]split=3[v0][v1][v2]; [v0]fps=60, settb=AVTB,setpts='trunc(PTS/1K)*1K+st(1,trunc(RTCTIME/1K))-1K*trunc(ld(1)/1K)', drawtext=fontsize=30:box=1:boxcolor=black@0.75:fontcolor=white:text='%{localtime}.%{eif\:1M*t-1K*trunc(t*1K)\:d}', drawtext=text='1920p-6000K':x=w-tw:y=h-th:fontsize=30:box=1:boxcolor=black@0.75:fontcolor=white, scale=1920x1080:flags=bicubic[v0final]; [v1]fps=30, settb=AVTB,setpts='trunc(PTS/1K)*1K+st(1,trunc(RTCTIME/1K))-1K*trunc(ld(1)/1K)', drawtext=fontsize=30:box=1:boxcolor=black@0.75:fontcolor=white:text='%{localtime}.%{eif\:1M*t-1K*trunc(t*1K)\:d}', drawtext=text='1280p-5000K':x=w-tw:y=h-th:fontsize=30:box=1:boxcolor=black@0.75:fontcolor=white, scale=1280x720:flags=bicubic[v1final]; [v2]fps=25, settb=AVTB,setpts='trunc(PTS/1K)*1K+st(1,trunc(RTCTIME/1K))-1K*trunc(ld(1)/1K)', drawtext=fontsize=30:box=1:boxcolor=black@0.75:fontcolor=white:text='%{localtime}.%{eif\:1M*t-1K*trunc(t*1K)\:d}', drawtext=text='640p-4000K':x=w-tw:y=h-th:fontsize=30:box=1:boxcolor=black@0.75:fontcolor=white, scale=640x480:flags=bicubic[v2final]" -map "[v0final]" -map "[v1final]" -map "[v2final]" -map 0:a -c:v:0 libx264 -profile:v high -preset veryfast -tune zerolatency -b:v 6000K -maxrate 6600K -minrate 5400K -bufsize 12000K -keyint_min 60 -g 60 -x264-params "keyint=60:scenecut=0:bframes=0" -c:v:1 libx264 -profile:v high -preset veryfast -tune zerolatency -b:v 5000K -maxrate 5500K -minrate 4500K -bufsize 10000K -keyint_min 30 -g 30 -x264-params "keyint=30:scenecut=0:bframes=0" -c:v:2 libx264 -profile:v high -preset veryfast -tune zerolatency -b:v 4000K -maxrate 4400K -minrate 3600K -bufsize 8000K -keyint_min 25 -g 25 -x264-params "keyint=25:scenecut=0:bframes=0" -c:a copy -f mpegts pipe:1 | ffprobe -hide_banner -select_streams v -show_entries stream=r_frame_rate pipe:0
Input #0, mpegts, from 'pipe:0':
  Duration: N/A, start: 1.400000, bitrate: N/A
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
  Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 60 fps, 60 tbr, 90k tbn
  Stream #0:1[0x101]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 30 fps, 30 tbr, 90k tbn
  Stream #0:2[0x102]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 640x480 [SAR 4:3 DAR 16:9], 25 fps, 25 tbr, 90k tbn
  Stream #0:3[0x103](und): Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 130 kb/s

Since the input file ./dev/bbb.fmp4 is in 24 fps , I had set the default value as videofps=25

ffprobe -hide_banner -select_streams v -show_entries stream=r_frame_rate ./dev/bbb.fmp4
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from './dev/bbb.fmp4':
  Metadata:
    major_brand     : iso6
    minor_version   : 512
    compatible_brands: iso6cmfcmp41
    encoder         : Lavf59.27.100
  Duration: 00:09:56.47, start: 0.000000, bitrate: 2176 kb/s
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 1991 kb/s, 24 fps, 24 tbr, 24k tbn (default)

I second the idea of using a 60-fps input file as it gives more flexibility to downscale/manipulate the frame rate for different output streams, and I would recommend using -r as it ensures ffmpeg correctly interprets the input frame rate.

@Manuel-Barrabino
Copy link
Author

Understood, I'll add the -r before the input and try to add a new 60fps reliable source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants