Table of Contents

ffmpeg - Conversions - Convert H265 to H264

Software Encoding

Using ffmpeg

ffmpeg -i input.mkv -c copy output.mp4

Matroska output

mkdir h264vids
for f in *.mp4; do ffmpeg -i "$f" -map 0 -c copy -c:v libx264 -crf 23 -preset medium h264vids/"${f%.*}.mkv"; done

See FFmpeg Wiki: H.264 for more info on these options.


MP4 output

This example is a little more complicated.

This will perform conditional encoding depending if the input audio is AAC or not.

If the input audio is AAC then the audio will be stream copied (re-muxed) as is and needless re-encoding is avoided.

If the input audio is not AAC then it will be re-encoded to AAC.

#!/bin/bash
 
mkdir h264vids
 
for f in *.mkv
do
  audioformat=$(ffprobe -loglevel error -select_streams a:0 -show_entries stream=codec_name -of default=nw=1:nk=1 "$f")
  if [ "$audioformat" = "aac" ]; then
    ffmpeg -i "$f" -c:v libx264 -crf 23 -preset medium -c:a copy -movflags +faststart h264vids/"${f%.*}.mp4"
  else
    ffmpeg -i "$f" -c:v libx264 -crf 23 -preset medium -c:a aac -movflags +faststart h264vids/"${f%.*}.mp4"
  fi
done

Using ffmpeg

for file in *265.mkv; do nice -n19 ffmpeg -i $file -c copy -c:v libx264 ${file/%265.mkv/264.mkv}; done

Using libav

sudo apt-get install libav-tools
avconv -i oldvideo.mkv -ar 22050 convertedvideo.mp4