0

I want to do something similar to the one on this guide but in that case both inputs have the same fps, I want to sync two distinct framerate inputs, here a sample:

ffmpeg \
  -f x11grab \
  -video_size 1920x1080 \
  -framerate 60 \
  -i :0.0 \
  -f v4l2 \
  -video_size 320x240 \
  -framerate 15 \
  -i /dev/video0 \
  -filter_complex '[0:v][1:v]overlay=10:(H-h)/2[o]' \
  -map '[o]' \
  -r 60 \
  -vcodec libx264 \
  -an \
  -f mpegts \
  udp://127.0.0.1:3333

Then to watch: vlc udp://@127.0.0.1:3333

In my case it awkwardly gives about 10 fps and seems to be freezing, though I expected 60 I believe it would be more likely to be 15 since it is the lowest one, who knows...

However if I remove the webcam input and the filter it gives the full 60 fps I wanted, as well as when I stream only the webcam it gives the 15 fps.

Based on this other guide I also tried the filter [1:v]fps=fps=60[wc];[0:v][wc]overlay=10:(H-h)/2[o] but with no success.

I expect the output fps to be 60 and the frames to be nicely distributed someway avoiding the freezing effect. How can I sync two different fps videos inputs with ffmpeg?

Evidences:

4
  • Not clear what you mean by sync. Do you mean output speed? – Gyan Sep 4 '20 at 5:17
  • Somehow, I expect the output fps to be 60, but I also want the frames to be nicely distributed, if you run the command you see it seems to pick the first 10 frames, then drop the next 50, the result seems a freezing video. – Tiago Pimenta Sep 4 '20 at 5:35
  • Share full log. – Gyan Sep 4 '20 at 9:51
  • @Gyan I attached the logs on the question, also the video. – Tiago Pimenta Sep 4 '20 at 11:51
0

I still don't know exactly why, but the following worked:

ffmpeg \
  -f x11grab \
  -video_size 1920x1080 \
  -framerate 60 \
  -i :0.0 \
  -f v4l2 \
  -video_size 320x240 \
  -framerate 15 \
  -i /dev/video0 \
  -filter_complex '[0:v]setpts=RTCTIME-RTCSTART[dt];[1:v]setpts=PTS-STARTPTS[wc];[dt][wc]overlay=10:(H-h)/2[o]' \
  -map '[o]' \
  -r 60 \
  -vcodec libx264 \
  -an \
  -f mpegts \
  udp://127.0.0.1:3333

Although the documentation said RTCTIME is deprecated, and most people use PTS-STARTPTS, it seems I forced the stream to be time based stead of a number sequence.

Edit:

With the following filter also works and I believe it is better suitable:

[0:v]setpts=N/FRAME_RATE/TB[dt];[1:v]setpts=N/FRAME_RATE/TB,fps=fps=60[wc];[dt][wc]overlay=10:(H-h)/2[o]

It insures the fixed framerate and also adjust the webcam to have the same one as expected on the output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.