Convert .ts to .mp4

ffmpeg -i input.ts -vcodec copy -acodec copy output.mp4
# or 
ffmpeg -i input.ts -c copy output.mp4

List codec & format

ffmpeg -codecs
ffmpeg -formats

Convert h265 video to h264

# Default
ffmpeg -i input.mp4 -vcodec h264 output.mp4
 
# Speed up with quicksync
ffmpeg -i input.mp4 -vcodec h264_qsv output.mp4
 
# Speed up with amf
ffmpeg -i input.mp4 -vcodec h264_amf output.mp4

Convert audio to aac

ffmpeg -i input.mp4 -vcodec copy -acodec aac -movflags faststart output.mp4
-----
#!/bin/bash
for input_file in ./*.mp4; do
  filename=$(basename -- "$input_file")
  filename="${filename%.*}"
  output_file="./output-$filename.mp4"
  ffmpeg -i "$input_file" -c:v copy -c:a aac -movflags faststart "$output_file"
done
-----

Find & convert files to mp4

# Find & convert .mkv to .mp4
find . -name "*.mkv" | xargs -I {} ffmpeg -i "{}" -vcodec copy -acodec aac -movflags faststart "{}.mp4"
 
# Find & convert .mkv to .mp4
find . -name "*.flv" | xargs -I {} ffmpeg -i "{}" -vcodec copy -acodec aac -movflags faststart "{}.mp4"  
 
# Remove .mkv or .flv  files
find . -name "*.mkv" | xargs -I {} rm -rf {}  
find . -name "*.flv" | xargs -I {} rm -rf {}  
  
# Rename `.mkv.mp4` or `.flv.mp4` to `.mp4`  
find . -name "*.mkv.mp4" | xargs -I {} rename -n 's/mkv\.mp4/mp4/g' {}  
find . -name "*.flv.mp4" | xargs -I {} rename -n 's/flv\.mp4/mp4/g' {}

Combine multi video

vim files.txt  
-----
file '1.mp4'
file '2.mp4'
file '3.mp4'
-----
 
ffmpeg -f concat -safe 0 -i files.txt -c copy -movflags faststart output.mp4
 
# or
 
ffmpeg -i 'concat:1.mp4|2.mp4' -c copy output.mp4  

# or:  

ffmpeg -i 1.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 1.ts  
ffmpeg -i 2.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 2.ts  
ffmpeg -i "concat:1.ts|2.ts" -acodec copy -vcodec copy -absf aac_adtstoasc output.mp4

Separate audio and video

ffmpeg -i input.mp4 -c aac -vn output_audio.aac
ffmpeg -i input.mp4 -c copy -an output_video.mp4

Combine audio & video

ffmpeg -i output_video.mp4 -i output_audio.aac -c copy -strict experimental -movflags faststart output_merged.mp4
 
ffmpeg -i output_video.mp4 -i output_audio.aac -c:v copy -c:a aac -strict experimental output.mp4

Add srt subtitles to video

ffmpeg -i input.mp4 -vf subtitles=subtitle.srt output.mp4