Playing 2x4k Videos on Dual Monitors with FFmpeg on Linux
In this article, we will cover how to play two 4k videos simultaneously on dual monitors connected to a Linux machine using FFmpeg. We will also discuss how to use ffplay to accomplish this task.
Prerequisites
To follow along with this article, you will need the following:
- A Linux machine with dual monitors
- FFmpeg installed
- Two 4k videos with the same length
Playing 4k Videos on Dual Monitors with FFmpeg
To play two 4k videos on dual monitors with FFmpeg, you can use the following command:
ffmpeg -i video1.mp4 -i video2.mp4 -filter\_complex "[0:v]setpts=PTS-STARTPTS[v0];[1:v]setpts=PTS-STARTPTS[v1];[v0][0:a][v1][1:a]concat=n=2:v=1:a=1[outv][outa]" -map "[outv]" -map "[outa]" -c:v libx264 -crf 18 -preset veryfast -b:v 5000k -maxrate 5000k -bufsize 2000k -vf "format=yuv420p,scale=-2:2160" -c:a aac -b:a 128k -ar 48000 -f tee "[f=nut] /dev/null | [f=nut] [0:v] [0:a] >(ffplay -autoexit -fflags +genpts -i /dev/stdin)" "[f=nut] [1:v] [1:a] >(ffplay -autoexit -fflags +genpts -i /dev/stdin)"Let's break down this command:
-i video1.mp4 -i video2.mp4: These options specify the input files for the two videos.-filter\_complex: This option is used to specify the filter graph for FFmpeg.[0:v]setpts=PTS-STARTPTS[v0];[1:v]setpts=PTS-STARTPTS[v1]: These filters are used to set the presentation timestamp for the two videos.[v0][0:a][v1][1:a]concat=n=2:v=1:a=1[outv][outa]: This filter is used to concatenate the two videos and audio streams.-map "[outv]" -map "[outa]": These options are used to map the output video and audio streams to the final output.-c:v libx264 -crf 18 -preset veryfast -b:v 5000k -maxrate 5000k -bufsize 2000k -vf "format=yuv420p,scale=-2:2160": These options are used to specify the video codec, bitrate, and scaling.-c:a aac -b:a 128k -ar 48000: These options are used to specify the audio codec, bitrate, and sample rate.-f tee: This option is used to split the output into two separate streams."[f=nut] /dev/null | [f=nut] [0:v] [0:a] >(ffplay -autoexit -fflags +genpts -i /dev/stdin)" "[f=nut] [1:v] [1:a] >(ffplay -autoexit -fflags +genpts -i /dev/stdin)": These options are used to play the two output streams on the dual monitors using ffplay.
Using ffplay to Play 4k Videos on Dual Monitors
If you prefer to use ffplay to play the 4k videos on dual monitors, you can use the following command:
ffplay -fflags +genpts -i video1.mp4 -autoexit -vf "format=yuv420p,scale=-2:2160" -window\_title "Monitor 1" -geometry 3840x2160+0+0 & ffplay -fflags +genpts -i video2.mp4 -autoexit -vf "format=yuv420p,scale=-2:2160" -window\_title "Monitor 2" -geometry 3840x2160+3840+0
Let's break down this command:
-fflags +genpts: This option is used to generate timestamps for the input files.-i video1.mp4: This option is used to specify the input file for the first video.-autoexit: This option is used to exitffplaywhen the input file ends.-vf "format=yuv420p,scale=-2:2160": These options are used to specify the video format and scaling.-window\_title: This option is used to set the window title for theffplaywindow.-geometry: This option is used to specify the window position and size for theffplaywindow.&: This option is used to run the twoffplaycommands in the background.
- In this article, we discussed how to play two 4k videos simultaneously on dual monitors connected to a Linux machine using FFmpeg.
- We covered how to use the
ffmpegcommand to concatenate the two videos and audio streams and play them on the dual monitors using ffplay. - We also discussed how to use the
ffplaycommand directly to play the two 4k videos on the dual monitors.