Mpv: [Feature request?] Play multiple videos sides by sides

Created on 29 Nov 2016  Â·  15Comments  Â·  Source: mpv-player/mpv

Hi everyone,

Maybe this is not the right place for this, or maybe this feature already exist and I’ve missed it or they are existing third-party tool allowing this, in which case I suppose someone will be kind enough to show me the right direction. ;)

I have a use case where I would like to play multiple videos side by side (OK, until there nothing my WM can’t do), but synchronously (and that’s the thing). They all have the same duration and resolution (or at least aspect ratio).

Ideally, I would like to choose how the videos are placed with regard to each other, but I could definitively live with a fixed setup for 2, 3 and 4 streams (which I consider a reasonable limit for the feature to be useful, unless you have a very big screen).

In my case, the splitting for 2 streams would be left/right halves of the screen for instance, but maybe it could be upper/lower ones depending on the aspect ratio in other cases. For 4 streams, 4 corners, but again that could depend on aspect ratio. For 3 stream, maybe 4 corners with a black one. Ditto.

Since this looks like lot of work in mpv for a certainly not high priority feature (if desirable at all), I was wondering whether this splitting could be left at the user responsibility (which can then use whatever — tiling for instance — WM he wants), while providing a way to synchronise multiple mpv instances.

Is there a way to do so? Else, could it be done?

Thanks in advance, and keep doing great work!

Most helpful comment

Awesome! “Probably slow” is no issue for me, it’s 1000×800@5fps streams that I have. ;) Thanks both of you for your help.

So, if anyone is looking for this, here is what I ended up doing:

  • 2 videos: mpv <video1> --external-file=<video2> --lavfi-complex='[vid1] [vid2] hstack [vo]'
  • 4 videos: mpv <video1> --external-file=<video2> --external-file=<video3> --external-file=<video4> --lavfi-complex='[vid1] [vid2] hstack [t1] ; [vid3] [vid4] hstack [t2] ; [t1] [t2] vstack [vo]'

hstack can be changed to vstack and reciprocally, depending on what you want to achieve in terms of disposition. ;)

I consider this as solved, thanks again!

P.S.: Side question, while doing this I’ve discovered that hwdec (VAAPI here) wasn’t working for yuv444p streams (it’s more obvious when written 4 times than one), I suppose this is libva or hardware support issue?

All 15 comments

Maybe it is already possible through --lavfi-complex option.
check:
https://trac.ffmpeg.org/wiki/Create%20a%20mosaic%20out%20of%20several%20input%20videos

Yes, you can make mpv open several files with --external-file or whatever it was, and then stack them together using lavfi-complex.

Probably slow.

Awesome! “Probably slow” is no issue for me, it’s 1000×800@5fps streams that I have. ;) Thanks both of you for your help.

So, if anyone is looking for this, here is what I ended up doing:

  • 2 videos: mpv <video1> --external-file=<video2> --lavfi-complex='[vid1] [vid2] hstack [vo]'
  • 4 videos: mpv <video1> --external-file=<video2> --external-file=<video3> --external-file=<video4> --lavfi-complex='[vid1] [vid2] hstack [t1] ; [vid3] [vid4] hstack [t2] ; [t1] [t2] vstack [vo]'

hstack can be changed to vstack and reciprocally, depending on what you want to achieve in terms of disposition. ;)

I consider this as solved, thanks again!

P.S.: Side question, while doing this I’ve discovered that hwdec (VAAPI here) wasn’t working for yuv444p streams (it’s more obvious when written 4 times than one), I suppose this is libva or hardware support issue?

Non-yuv420p hwaccel support is rare/nonexistent.

@wiiaboo Thanks.

Closing this as solved. :)

Oh, and one other thing: is there a way to avoid this ugly multiple --external-file=? I’ve tried multiple things like , or : separators between files, to no avail. Should I open a new FR for external-file to support multiple files, or did I miss something again?

--external-file={video1,video2}?

I don't think it does separators.

@wiiaboo That did it, thanks! Wonder why I haven’t tried that…

Funny thing: this doesn’t work with hwdec anyway. After converting my videos to yuv420p (well, generating them directly to this format to be exact), I’ve stumbled upon this:

[ffmpeg] Impossible to convert between the formats supported by the filter 'mpv_src_vid1' and the filter 'auto-inserted scaler 0'
failed to configure the filter graph

And then mpv stops. But as the doc says:

Most video filters will not work with hardware decoding as they are primarily implemented on the CPU. Some exceptions are vdpaupp, vdpaurb and vavpp. See VIDEO FILTERS for more details.

Let’s use vaapi-copy. ;) Thanks again everyone for your great and appreciated help! :)

@ArchangeGabriel is there a way to do this side by side compare of videos of different resolutions?

is there a way to do this side by side compare of videos of different resolutions?

You can use a scale filter to get one to the size of the other, or scale each to half your screen, or whatever. The manual does mention this, but here are a couple examples:

mpv somevideo720.mkv --external-file=somevideo1080.mkv --lavfi-complex='[vid1] scale=1920x1080 [vid1_scale]; [vid1_scale][vid2] hstack [vo]'
mpv somevideo720.mkv --external-file=somevideo1080.mkv --lavfi-complex='[vid1] scale=960x540 [vid1_scale]; [vid2] scale=960x540 [vid2_scale]; [vid1_scale][vid2_scale] hstack [vo]'



md5-abc8ded42eb55a8324aaaff4a5c0fb4c



mpv somevideo720.mkv --external-file=somevideo1080.mkv --lavfi-complex='[vid1] scale=1920x1080:flags=spline [vid1_scale]; [vid1_scale][vid2] hstack [vo]'

mpv by default will still re-scale the result if your window size is different from that of the combined videos. You can prevent that with --video-unscaled.

is there a way to do this side by side compare of videos of different resolutions?

You can use a scale filter to get one to the size of the other, or scale each to half your screen, or whatever. The manual does mention this, but here are a couple examples:

mpv somevideo720.mkv --external-file=somevideo1080.mkv --lavfi-complex='[vid1] scale=1920x1080 [vid1_scale]; [vid1_scale][vid2] hstack [vo]'
mpv somevideo720.mkv --external-file=somevideo1080.mkv --lavfi-complex='[vid1] scale=960x540 [vid1_scale]; [vid2] scale=960x540 [vid2_scale]; [vid1_scale][vid2_scale] hstack [vo]'

That won't use mpv's own high-quality gpu scaling. You can change the scaling algorithm ffmpeg uses by giving flags to the scale filter:

mpv somevideo720.mkv --external-file=somevideo1080.mkv --lavfi-complex='[vid1] scale=1920x1080:flags=spline [vid1_scale]; [vid1_scale][vid2] hstack [vo]'

mpv by default will still re-scale the result if your window size is different from that of the combined videos. You can prevent that with --video-unscaled.

I find the filters complex. Is it similar to ffmpeg's filter_complex or lavfi?

Is it similar to ffmpeg's filter_complex or lavfi?

It is exactly the same as that, AFAIK.

Filtergraph syntax is documented in ffmpeg-filters(1).
mpv-specific bits are documented in its own manual.

The label names (for track selection) are different, otherwise the graph syntax is the same.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

szg0000 picture szg0000  Â·  3Comments

WoLpH picture WoLpH  Â·  3Comments

ghost picture ghost  Â·  3Comments

laichiaheng picture laichiaheng  Â·  3Comments

xanadupark picture xanadupark  Â·  3Comments