Is there a possibility for a batch conversion of video files (different formats) and delete metadata with ffmpeg?
I have a lot of video files of my family. I'am on Windows and the video formats are different:
Video files:
DVD directories contain:
Files in DVD directories were recorded with a DVD recorder and then copied from the DVD to my computer hard disk.
Let say the above directory D:\ffmpeg
is my work directory for ffmpeg
. Which means all video files are stored there.
My wish is to convert each file to mp4
and mkv
(for test purpose). For example the input file test.avi
should give two output files test.mp4
and test.mkv
. The output files should have the same properties as the input files. Important for me are screen size, aspect ratio and frame rate. Video and audio quality should stay nearly the same, so that the difference is imperceptible. The audio codec should only fullfill the audio quality an can be for example aac
, mp3
, flac
or vorbis
. I don't know if ffmpeg
can take the audio/video quality (kb per s) settings from the source files for the output files. The video codec should be h.265
, if even possible. The menus of DVD (if present) files should be dropped and the DVD source files should be merged to one output file.
Till now I never worked with ffmpeg
. I only read about current common audio/video codecs and video file formats. Why I wish to go this way? Many gui video editing programs are overloaded and expensive. Free gui programs maybe can't do such things. The important thing is with options of ffmpeg
I have the full control of what will be done.
By the way all deletable metadata in the output files should be deleted.
So, now I downloaded the ffmpeg
binary from here, copied it to the above directory and need to type something like this:
ffmpeg [--option1 ... --optionN] [source files list in the current directory] [output files list]
Is it possible to solve my task with only one run? If not, I naturally welcome a solution for each file format or something different, if it make more sense. You are naturally free to suggest other useful option settings for ffmpeg
, if it would help in general to solve this task.
I hope I described the task clear enough. If not, let me know it.
Please don't answer with "Read the ffmpeg
manual"
or "Use the program xyz
instead".
Thank you for your help and effort in advance!
Solution 1:
Yes, this is possible with ffmpeg
. However, as a command-line tool, it's expected that any processing will be scripted. While it's possible to run it on multiple files at once, it's both easier and cleaner to run ffmpeg
on each file separately. From the Linux man page:
ffmpeg reads from an arbitrary number of input "files" (which can be
regular files, pipes, network streams, grabbing devices, etc.),
specified by the "-i" option, and writes to an arbitrary number of
output "files", which are specified by a plain output url. Anything
found on the command line which cannot be interpreted as an option is
considered to be an output url.
[...]
As a general rule, options are applied to the next specified file.
Therefore, order is important, and you can have the same option on the
command line multiple times. Each occurrence is then applied to the
next input or output file. Exceptions from this rule are the global
options (e.g. verbosity level), which should be specified first.
Do not mix input and output files -- first specify all input files,
then all output files. Also do not mix options which belong to
different files. All options apply ONLY to the next input or output
file and are reset between files.
Also, when given multiple input files, by default ffmpeg will automatically attempt to map streams between them "optimally" — if you want linear mapping input:output, you have to specify it yourself.
So unless you feel like building command lines like this:
ffmpeg -i file1.avi -i file2.avi -i file3.avi \
-map 0:a -map 0:v -c:v h265 -c:a aac file1.mp4 \
-map 1:a -map 1:v -c:v h265 -c:a aac file2.mp4 \
-map 2:a -map 2:v -c:v h265 -c:a aac file3.mp4
You're far better off just running three separate ffmpeg
commands:
ffmpeg -i file1.avi -c:v h265 -c:a aac file1.mp4
ffmpeg -i file2.avi -c:v h265 -c:a aac file2.mp4
ffmpeg -i file3.avi -c:v h265 -c:a aac file3.mp4
That's just plain simpler, it's actually shorter, and it's way easier to script.
Multi-format
Creating both mp4
and mkv
files is more than a little redundant, since those are simply container formats — if you encode into both files using the same codecs, they'll contain exactly the same audio and video data. So there will be no detectable difference in quality or content or anything, if that's what you mean by "testing purposes".
If you're testing the two containers to gauge compatibility with different playback devices or something, that's a different story, but I'd suggest only creating one or two pairs of both-formats conversions, rather than wasting time doing all of them.
If you wanted to create them both at the same time to save encoding time, you'd have to get into complexities of filtergraphs and splitting. You'd be much better off encoding to one output format and then remuxing to the other using:
ffmpeg -i file1.mp4 -codec copy file1.mkv
That will at least be very quick, and it emphasizes the fact that the files contain exactly the same audio and video stream data, making the whole exercise a bit pointless.
DVDs
For your DVD content, ffmpeg
can of course read VOB
files, but it can't analyze a directory of them, pick out only the main content, and choose which pieces to encode together into an output file. You'd have to do that discovery yourself.
As mentioned, HandBrake is really a far, far superior tool, and handles all that crap. It uses ffmpeg
to do its processing anyway, so you're still using it. (You'd be hard pressed to find a free/open-source video/audio processing tool that doesn't use ffmpeg, or at least its libraries. Heck, most commercial tools use it too.)
Or, mkvmerge-gui
(part of MKVToolNix, also a free tool) can take a list of VOB
files as serialized input segments, and reencode them as a single .mkv
file pretty painlessly. (I actually like MKVToolNix a bit better than HandBrake, for just straight-up transcoding, but I still have to manually decide exactly which .VOB
pieces I want it to process.)
Solution 2:
Use a batch script to call ffmpeg. Place the script in the folder with your files. Make sure that ffmpeg in your path.
set /a fname=0
for %%f in (*.avi) do (
ffmpeg -i "%%~f" -c:v libx265 "!fname!.mp4"
set /a fname=!fname!+1
)
fname
is a counter that will name your files with a unique name.
The actual conversion is done using defaults -
ffmpeg -i "%%~f" -c:v libx265 "!fname!.mp4"
Alternatively, use any ffmpeg-based GUI. Some include :-
shutter encoder - https://www.shutterencoder.com/en/ or YAG - https://sourceforge.net/projects/ffmpegyag/