batch video conversion using command line FFMPEG - avi to mp4

https://trac.ffmpeg.org/wiki/Encode/H.264

I have a video game’s series downloadable videos which is a mix of avi and mp4. The witcher 1,2,&3 on GOG.
#1&2 are AVI format
#3 is mp4.

Note: some videos have subtitle files. I don’t know if I can play videos with a subtitle file on BRP’s USB port.

My Blueray player plays MP4 video format, but not AVI, using a USB port.

I want to keep the quality of the avi format or improve it. Without an API, I need command line batch conversion from AVI to MP4.

ffmpeg -i file.avi file.mp4

This works. I tried wild cards to no effect. I can write a full script conversion.

If there is a good command line batch conversion, what are my options?

Fine.

Wild cards, where? And what were your expectations of them?

Fine.

I would say when the basic conversion works and you can write a script around it to do somethng more (that you do not explain or describe), the what is your question?

First,
When you’re using a particular technology, learn the terminology.
No one can know if you know what your’e doing when you use a word like “format” for what you’re doing… AVI and MP4 are types of “containers” which should give you a hint about their functionality and relevance to what you’re doing… which is next to nil. A “container” helps to associate the file with a “viewer” or “player” application, but has little to do with the encoding of the multimedia file.

The essential aspect of the file is the encoding, and we use a type of library file called a “codec” (which is an abbreviation and combination of “encode” and “decode” to denote the file can be used for both purposes) to read or create new encoded files… and ffmpeg is a collection of these codecs (there are other collections like gstreamer).

Your first step is to identify the codec your file is originally encoded, and then decide what codec you wish to re-encode.
A useful tool to identify the current encoding of any multimedia file is Mediainfo.

More info can be found in numerous guides, the ffmpeg help and MAN files.

TSU

I can’t help with keeping the subtitle files in a script … you could extract those, and add them later. But its incredibly easy to do a batch conversion of .avi to.mp4.

Put all the .avi files in one directory, open a konsole/xterm, navigate to that directory, and send this simple command:


for i in *.avi; do ffmpeg -i "$i" "$i".mp4; done 

Of course that command can be made far more complex, to do things automatically on the .avi, prior to saving it to a .mp4.

Also, you may not like the name of the file with the above loop, … so instead you could use this:


for i in *.avi; do ffmpeg -i "$i" ${i/%avi/mp4}; done

ffmpeg -i *.avi *.mp4
ffmpeg -i '*.avi' '*.mp4'

I would say when the basic conversion works and you can write a script around it to do something more (that you do not explain or describe), the what is your question?

Conversion of all files in folder from avi to mp4 format (codec). Both sets of code don’t work.

Folder:
file1.avi
file2.avi
file3.avi

Output: folder

file1.avi
file2.avi
file3.avi

file1.mp4
file2.mp4
file3.mp4

I can write the script, but if it exists already. I want to use it.

Containers are the file. The codec is how that file is encoded. Source is a digital download, not dvd.



#mediainfo 'The Witcher - Archive Materials - Music and Sound.avi'        
General
Complete name                            : The Witcher - Archive Materials - Music and Sound.avi
Format                                   : AVI
Format/Info                              : Audio Video Interleave
File size                                : 74.6 MiB
Duration                                 : 3 min 15 s
Overall bit rate                         : 3 203 kb/s
Writing application                      : Lavf53.21.0
Original source form/Name                : THE_WITCHER_DVD

Video
ID                                       : 0
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : Main@L3.1
Format settings                          : CABAC / 2 Ref Frames
Format settings, CABAC                   : Yes
Format settings, ReFrames                : 2 frames
Codec ID                                 : H264
Duration                                 : 3 min 15 s
Bit rate                                 : 2 998 kb/s
Width                                    : 960 pixels
Height                                   : 540 pixels
Display aspect ratio                     : 16:9
Frame rate                               : 25.000 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.231
Stream size                              : 69.8 MiB (94%)
Writing library                          : x264 core
Color range                              : Limited
Color primaries                          : BT.601 NTSC
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.601

Audio
ID                                       : 1
Format                                   : MPEG Audio
Format version                           : Version 1
Format profile                           : Layer 3
Format settings                          : Joint stereo
Codec ID                                 : 55
Codec ID/Hint                            : MP3
Duration                                 : 3 min 15 s
Bit rate mode                            : Constant
Bit rate                                 : 192 kb/s
Channel(s)                               : 2 channels
Sampling rate                            : 48.0 kHz
Compression mode                         : Lossy
Stream size                              : 4.47 MiB (6%)
Alignment                                : Aligned on interleaves
Interleave, duration                     : 24  ms (0.60 video frame)

#exitftool 'The Witcher - Archive Materials - Music and Sound.avi'        
ExifTool Version Number         : 10.80
File Name                       : The Witcher - Archive Materials - Fighting Part 1.avi
Directory                       : .
File Size                       : 66 MB
File Modification Date/Time     : 2012:07:04 05:32:22-07:00
File Access Date/Time           : 2019:11:18 21:13:25-08:00
File Inode Change Date/Time     : 2019:11:15 22:58:21-08:00
File Permissions                : rw-r--r--
File Type                       : AVI
File Type Extension             : avi
MIME Type                       : video/x-msvideo
Frame Rate                      : 25
Max Data Rate                   : 389.6 kB/s
Frame Count                     : 4343
Stream Count                    : 2
Stream Type                     : Video
Video Codec                     : H264
Video Frame Rate                : 25
Video Frame Count               : 4343
Quality                         : Default
Sample Size                     : Variable
BMP Version                     : Unknown (79)
Image Width                     : 960
Image Height                    : 540
Planes                          : 1
Bit Depth                       : 24
Compression                     : H264
Image Length                    : 1555200
Pixels Per Meter X              : 0
Pixels Per Meter Y              : 0
Num Colors                      : Use BitDepth
Num Important Colors            : All
Red Mask                        : 0x01000000
Green Mask                      : 0x1f404d67
Blue Mask                       : 0x8007769a
Alpha Mask                      : 0x0635f78b
Color Space                     : Unknown (4195841)
Audio Codec                     : .
Audio Sample Rate               : 24000
Audio Sample Count              : 4126464
Encoding                        : MP3
Num Channels                    : 2
Sample Rate                     : 48000
Avg Bytes Per Sec               : 24000
Bits Per Sample                 : 0
Product                         : THE_WITCHER_DVD
Software                        : Lavf53.21.0
Duration                        : 0:02:53
Image Size                      : 960x540
Megapixels                      : 0.518
lehann_beinne@linux-uucq:~/Temp_Folder/The_Witcher/the_witcher_behind_the_scenes/The Witcher - Archive Materials> exiftool 'The Witcher - Archive Materials - Fighting Part 1.avi'
ExifTool Version Number         : 10.80
File Name                       : The Witcher - Archive Materials - Fighting Part 1.avi
Directory                       : .
File Size                       : 66 MB
File Modification Date/Time     : 2012:07:04 05:32:22-07:00
File Access Date/Time           : 2019:11:18 21:13:25-08:00
File Inode Change Date/Time     : 2019:11:15 22:58:21-08:00
File Permissions                : rw-r--r--
File Type                       : AVI
File Type Extension             : avi
MIME Type                       : video/x-msvideo
Frame Rate                      : 25
Max Data Rate                   : 389.6 kB/s
Frame Count                     : 4343
Stream Count                    : 2
Stream Type                     : Video
Video Codec                     : H264
Video Frame Rate                : 25
Video Frame Count               : 4343
Quality                         : Default
Sample Size                     : Variable
BMP Version                     : Unknown (79)
Image Width                     : 960
Image Height                    : 540
Planes                          : 1
Bit Depth                       : 24
Compression                     : H264
Image Length                    : 1555200
Pixels Per Meter X              : 0
Pixels Per Meter Y              : 0
Num Colors                      : Use BitDepth
Num Important Colors            : All
Red Mask                        : 0x01000000
Green Mask                      : 0x1f404d67
Blue Mask                       : 0x8007769a
Alpha Mask                      : 0x0635f78b
Color Space                     : Unknown (4195841)
Audio Codec                     : .
Audio Sample Rate               : 24000
Audio Sample Count              : 4126464
Encoding                        : MP3
Num Channels                    : 2
Sample Rate                     : 48000
Avg Bytes Per Sec               : 24000
Bits Per Sample                 : 0
Product                         : THE_WITCHER_DVD
Software                        : Lavf53.21.0
Duration                        : 0:02:53
Image Size                      : 960x540
Megapixels                      : 0.518


AVI is not lossless format in sound and video?

From: Java Heap Space ... - jAlbum forums

Viewings jAlbums Image directory with the Smart TV via a DLNA Media Server is an interesting option. But most Smart TV do not support older video formats, such as .avi and .mov. Transcoding these videos with ffmpeg is painless and can be done issuing a single command:

**for** i in $(find Bilder/ -name *.mov) ; **do** ffmpeg -i $i -pix_fmt yuv420p ${i%*mov}mp4; done

Transcoding jAlbum’s input movies requires rebuilding videos and skin files. jAlbum was invoked as /usr/lib/jalbum/jre64/bin/java -jar /usr/lib/jalbum/JAlbum.jar and claimed some 3.5 GB of heap space (see screenshot) and another 20 GB of OS cache. Processing 680 video clips (12.1 GB, equivalent to several DVDs) took some 29 minutes to complete which compares favorably with total playtime of several hours.

The first code set works. The second gives an error:

[NULL @ 0x55958918a6a0] Unable to find a suitable output format for 'The'
The: Invalid argument


The filenames have spaces. So, I just changed it to this.

for i in *.avi; do ffmpeg -i "$i" "${i/%avi/mp4}"; done

That code works for batch conversion. I think I understand how it works.

Now, I need to understand more about video (and audio conversion). AVI (this file) is compressed in both audio and video, but not lossless format?

This converts mov to mp4 format keeping the original quality. What all the parms mean?

There is fine documentation: ffmpeg Documentation

Parameters are input file, -pix_fmt and output file. Omitting pix_fmt did not work for my Smart TV. When adding this parameter everything worked fine.

Thanks to all for the help. I understand enough to do most conversions. :slight_smile: