

See note above regarding -crf and -preset. mkv instance in the example to your input file type, or just use the greedy * by itself. This example will output to a directory named h264vids. Matroska output mkdir h264vidsįor f in *.mp4 do ffmpeg -i "$f" -map 0 -c copy -c:v libx264 -crf 23 -preset medium h264vids/"$.mp4" Then put the ffmpeg binary in ~/bin or /usr/local/bin (you may have to log out then log in for it to be noticed). Save yourself some trouble and download a recent version. These examples were written for recent ffmpeg.

Sleep 3 - allows the process to rest giving ffmpeg time to queue the next file This can be set up to send it to any directory you like. Mv "$i.ts" "$i.mpg" Converts the file extension to MPG in the same directory. ts format, this is useful so as not to overwrite your source files. This tells ffmpeg to encode the output to H.264 map is optional and can be discarded from the command. You can use ffprobe to view the streams available in the file. Other streams such as embedded subtitles are removed reducing the file size. This does two things, strips the excess audio streams, usually the first audio stream is English but not always. map 0:0 -map 0:1 Tells ffmpeg to only process the first two streams of the file ( 0:0 is the video stream, 0:1 is the first audio stream of the file). sn stops the streaming of subtitle streams (for those that do not want subtitles in their video) This is optional and can be removed. This is required by some streaming formats, typically the MPEG-2 transport stream format ( mpegts) processing MKV h.264 (currently)requires this, if is not included you will get an error in the terminal window instructing you to use it.

H264_mp4toannexb - Is the bit stream filter that is activated.Ĭonvert an H.264 bitstream from length prefixed mode to start code prefixed mode (as defined in the Annex B of the ITU-T H.264 specification). bsf:v activates the video bit stream filter to be used. This may be changed to accommodate the container extension of the files you wish to process.Įxecutes the program ffmpeg and calls for files to be processed. mkv files in a directory to be included in the batch process. This will convert to h.264 in an MPG container in the same directory. Open a terminal and direct it to the directory containing the H.265 encoded files, assuming you have ffmpeg and the appropriate libraries installed and assuming they are in MKV format copy and paste the following into the terminal window.
