2

I have a lot of video files of my family. I'am on Windows and the video formats are different:

Video files:

enter image description here

DVD directories contain:

enter image description here

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!

4
  • 1
    I understand that you don't want answers with "use this instead", but it may be worth it to look into the options you have with handbrake. Handbrake is a free and open source video transcoding tool that should be able to do all you want to do, from converting files to merging the DVD titles into a single container. Plus it allows batch processing, which makes it extremely useful in your case as you only have to give your parameters once and then select all the files you want to have processed. Sep 20, 2021 at 13:38
  • Hello @DarkDiamond! Thank you for your comment! Yes I wish to do it with ffmpeg. Why? Because I didn't have any experience in this area. I know that ffmpeg is very wide used and that ist the reason for my decision. I hoped to reseive an answer (for this for me very important task, because I have a lot of valuable videos of my family and friends, which now consume a lot of hard disk memory and are outdated formats/codecs/containers) which I can study (all the options and the command line using). The main difficulty for me is I don't know which options I have to use for which video format.
    – Su-47
    Sep 20, 2021 at 14:08
  • Ok, I understand your motivation to use ffmpeg. It is an absolutely amazing tool, and there is not much you cannot do with it. I myself can't do much with it, as I don't know it properly, and thought that going down that rabbit hole in my point in life is not the smartest thing to do. I can only recommend what I did, when this task came over me. I understand that this is not what you are looking for, but I thought I might share my approach with you, maybe you find it helpful although it is not an answer to your question. Sep 20, 2021 at 14:24
  • Hello @DarkDiamond! Maybe I came back later to your suggestion!
    – Su-47
    Sep 20, 2021 at 14:54

2 Answers 2

4

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.)

7
  • Hello @FeRD and @moi! Now is the whole thing much more clearly. Thank you both for the explanations! The only thing I miss till now, is which options for which video format/container/codec (*.3gp,*.avi,*.divx and so on, I guess I disorder this things) I have to use to achieve a compression for the audio/video stream, while the quality of both streams stay nearly the same, so that the difference for the human eyes is imperceptible or is it done with -c:v h.265 and respectively -c:a aac? If yes, why do you using h.265 and @moi libx265 instead? And how about -crf 28 -preset veryslow?
    – Su-47
    Sep 27, 2021 at 16:09
  • 2
    @Su-47 Unknown encoder 'h.265'. h.265 is a typo. You can use -c:v h265 instead, but that is a generic name and will choose whatever H.265 encoder is at the top of the list which can vary depending on your ffmpeg build. It is recommended to be specific and choose the encoder by name, such as -c:v libx265. As for -crf & -preset see FFmpeg Wiki: H.265/HEVC. Why spend time and effort on old, legacy, forgotten *.3gp,*.avi,*.divx? There are much better modern alternatives (H.264, HEVC, VP9, AV1, AAC, Opus, etc).
    – llogan
    Sep 27, 2021 at 16:35
  • 1
    @Su-47 For libx265 use the highest -crf value that still looks good enough as shown in the link in my previous comment. Then use this -crf value for all of your inputs. But it's best just to keep the old videos to avoid generation loss unless you really need to convert them.
    – llogan
    Sep 27, 2021 at 21:58
  • 1
    @Su-47 Keeping the difference in quality "imperceptible" is likely a losing goal, if that's your motivation then I have to agree with llogan that the generation loss will kill any benefits. However, for at least some of your content, the goal should be to convert it to look better than the original. I'm talking about the stuff that's encoded in interlaced format, using non-square pixels — played back in raw source form on a modern HD video display, that video tends to look... well, like crap, TBH. So I think there is value in converting away the quirks of legacy formats.
    – FeRD
    Sep 29, 2021 at 0:55
  • 1
    This thread at the Shotcut forum (although the venue isn't really relevant) covers a bunch of these issues, and has a lot of good information from smart people. But if you have video in interlaced, non-square-pixel formats like DVD, an ffmpeg pipeline that filters with something like -vf "bwdif,scale=1280:720,format=yuv422p" will ensure that your output video compensates for the interlacing/aspect as much as possible, and produces much more HD-compatible video out the back end.
    – FeRD
    Sep 29, 2021 at 1:00
4
+50

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/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .