Sunday, October 24, 2021

[SOLVED] vim diff fffmpeg output using command substitution

Issue

Why doesn't this work:

vim -d <(ffmpeg -i vid1.mp4 2>&1) <(ffmpeg -i vid2.mp4 2>&1) 

and how can I get it to work?

Currently it just clears my screen completely and causes my terminal to freeze, completely unresponsive to everything ctrl-c ctrl-d and ctrl-z. I have to quit my terminal every time.


Solution

You must use ffprobe (comes with ffmpeg) if you want an output suitable for diffing:

$ vim -d <(ffprobe -i vid1.mp4 2>&1) <(ffprobe -i vid2.mp4 2>&1)

Why?

ffmpeg is a media converter that outputs a lot of things during processing, including some information on the source file. Using it without providing an output file/stream/whatever only to get information on the source file is not how it is supposed to be used and, well… it just doesn't work correctly anyway: you get your information but the terminal may be left in a weird state and the operation returns a non-zero status.

By using ffmpeg, you are essentially relying on a side-effect of using the wrong tool incorrectly.

ffprobe, on the other hand, exists specifically for getting information on the source file.

By using ffprobe, you are relying on the expected outcome of using the right tool correctly.


That said, ffprobe probably shares a lot of code with ffmpeg because you need that 2>&1 hack to make its output Vim-friendly. Oh well…



Answered By - romainl