[FFmpeg-devel] [PATCH] ffmpeg: block output == input for files

Marton Balint cus at passwd.hu
Tue Aug 28 09:31:51 EEST 2018



On Tue, 28 Aug 2018, Gyan Doshi wrote:

>
> With some regularity, we have users trying to update input files using 
> ffmpeg, usually for the purposes of tagging, but occasionally for changing 
> the encoding or something else. Other apps like mp4box or taggers edit the 
> files in-place i.e. destination file is same as the source. FFmpeg cannot do 
> this. But since these users don't realize that, they will answer Yes to the 
> overwrite prompt and then discover their source has been destroyed.
>
> Attached patch checks the URL for file protocol outputs against inputs and 
> aborts upon a match. An option is provided for the user to force the 
> operation.
>
> The check isn't robust. In particular, it looks for exact url string matches, 
> so a command like
>
>    ffmpeg -i file:somefile -some_op somefile
>
> will still pass through. But I consider such invocations rare. Most times 
> I've seen users trying this (on Stackexchange or other support forums), the 
> command is typically of the form,
>
>    for i; do ffmpeg -i $i -some_op -y $i
>
> Such a scenario was filed as a bug in #4655 but it was marked as wontfix 
> since some protocols/services can manage bidir ops to the same endpoint. For 
> that reason, everything other than file protocol sources/sinks are exempt 
> i.e. http, pipes, devices..etc.
>
> This patch doesn't affect the semantics of '-y' and adds the check after it.

Instead of this, maybe we should add support to write lock the files when 
opening them for reading. Then ffmpeg can request this. That would be an 
useful option, and not just for unexperienced users.

Regards,
Marton


More information about the ffmpeg-devel mailing list