[FFmpeg-user] Is there a way to re-encode an inefficiently encoded file without losing quality and reducing file size?

Media Mouth communque at gmail.com
Sun Oct 1 04:37:05 EEST 2023


> On Sep 30, 2023, at 17:47, Stéphane Archer <archerstephane at gmail.com> wrote:
> 
> I'm not sure I understand what you mean, do you mean a hash like md5 and
> sha1?
> Could you please elaborate and simplify a bit?


I checked-- I was referencing this from your OP

> Is there any good reason why FFmpeg which sees that the video file input
> and output match every single characteristic doesn't copy the stream to
> avoid useless reencoding?
> Basically doing "-vcodec copy" automatically.

Based on that I was assuming you had existing files and arriving files new files that might or might not match your existing files
(Your actual situation may be different.  Might be helpful if you can provide more context about what you're trying to achieve.)

But to answer your question re hash: yes an md5 or sha.

I cobbled up a quick algorithm but instead of solving the problem it reveals a logic flaw

Take the following

ExistingFile = some file you might want to update
NewFile = The file that might update it.
ExistingFileHash = shasum -a 512 /path/to/ExistingFile
NewFileHash = shasum -a 512 /path/to/NewFile
if(NewFileHash <> ExistingFile){
	delete ExistingFile (or archive it, depending on your workflow)
	ffmpeg -i ExistingFile -whateversettings NewFile **Here's the logic flaw**
} else {
	Don't do anything to the ExistingFile
}

* An Existing File that was transcoded ffmpeg would never match hashes with a new file.  or if it did match, it would seem there's no reason to transcode it.

So it sounds like there's more to the story of what you're trying to achieve.

Are you maybe instead trying to see if the metadata of a NewFile matches stored metadata of an Existing file, and if not, then do a transcode?



More information about the ffmpeg-user mailing list