My note on ffmpeg usage




Most Common Basic Usage to burn subtitles into video
ffmpeg -i input.mp4 -vf subtitles="sub.srt" output.mp4
with gpu
ffmpeg -i input.mp4 -c:v hevc_amf -vf subtitles="sub.srt" output.mp4
ffmpeg -i input.mp4 -c:v h264_amf -vf subtitles="sub.srt" output.mp4 ffmpeg -i input.mp4 -c:v h264_nvenc -vf subtitles="sub.srt" output.mp4
Use this command to list down gpu option available
ffmpeg -f lavfi -i nullsrc -c:v h264_nvenc -gpu list -f null -


Below is the RAW note which I haven't tidy up.

Bash Shell Script for convert media file in batch.

for f in *.flv
do
#echo $f
#echo ${f%.*}
ffmpeg -i $f ./done/${f%.*}.mp4
done


rename 's/ACDC/AC-DC/' *.xxx

To replace # by somethingelse for filenames in the current directory (not recursive) you can use the GNU rename utility:

rename  's/#/somethingelse/' *

Characters like - must be escaped with a \.

ffmpeg -i orig.mkv -filter_complex "[0:v][0:s]overlay=(W-w)/2:(H-h)/10*9[v]" -map "[v]" -map 0:a output.mp4


ffmpeg -i 穿越時空的少女The\ Girl\ Who\ Leapt\ Through\ Time\ \(1\).mkv -filter_complex "[0:s]scale=iw/2:ih/2[ovr],[0:v][ovr]overlay=(W-w)/2:(H-h)/10*9.5[v]" -map "[v]" -map 0:a output.mp4

ffmpeg -i Guardians.of.the.Galaxy.Vol.2.2017.1080p.BluRay.x264.VPPV.mkv -vf subtitles="Guardians\ of\ the\ Galaxy\ Vol.\ 2\ \(2017\)\ \[1080p\]\ \[YTS.AG\].srt" out.mp4

for f in *.mkv
do
x=$(printf '%q' "$f")
#echo $x
#echo ${f%.*}
#echo "${x%.*}.ass"
#echo ${x%.*}

ffmpeg -i "$f" -vf subtitles="${x%.*}.ass" /Users/steven/Desktop/Dimension/"${f%.mkv}".mp4
done

for f in *.mp4
do
    new="${f%%.mp4} (CHT).mp4"
    subtitle="${f%%.mp4}.chi.ass"
    newsubtitle="${subtitle// /\\ }"
    echo $newsubtitle
    secsubtitle="${newsubtitle//[/\\[}"
    echo $secsubtitle
    thirdtitle="${secsubtitle//]/\\]}"
    echo $thirdtitle
    fourthtitle="${thirdtitle//(/\\(}"
    echo $fourthtitle
    fifthtitle="${fourthtitle//)/\\)}"
    echo $fifthtitle
    ffmpeg -i "$f" -vf subtitles="$fifthtitle" "$new"
done
new="${f%%.mp4}.CHT.mp4"
subtitle="${f%%.mp4}.chi.ass"
# make a temp hardlink to evade `ffmpeg`'s 
# onerous quoting requirements.
x=`mktemp -u -p . --suffix=.ass`
ln "$subtitle" $x
< /dev/null ffmpeg -i "$f" -vf subtitles=$x "${new}"
rm $x

remain same sound codec

ffmpeg -i Max\ Steel\ 2016\ 1080p\ BluRay\ x264\ DTS-JYK.mkv -vf subtitles="./Subs/English(SDH).srt" -acodec copy output.mp4

ffmpeg -i 双瞳.未删剪版.Double.Vision.Unrated.2002.D9.MiniSD-TLF.\(qvocd.com\).mkv -vf subtitles="双瞳.未删剪版.Double.Vision.Unrated.2002.D9.MiniSD-TLF.\(qvocd.com\).mkv":si=0 output.mp4

Only copy 1 audio stream

ffmpeg -i Sucker.Punch.BluRay.1080p.x264.5.1.HQ.Judas.mp4 -vf subtitles="Sucker.Punch.BluRay.1080p.x264.5.1.HQ.Judas.srt" -c:a:1 copy output.mp4

rearrange stream

ffmpeg -i 济公之神龙再现.mkv -map 0:0 -map 0:2 -map 0:1 -c copy output.mp4

crf 18

If you need to delay video by 3.84 seconds, use a command like this:

ffmpeg.exe -i "movie.mp4" -itsoffset 3.84 -i "movie.mp4" -map 1:v -map 0:a -c copy "movie-video-delayed.mp4"

If you need to delay audio by 3.84 seconds, use a command like this:

ffmpeg.exe -i "movie.mp4" -itsoffset 3.84 -i "movie.mp4" -map 0:v -map 1:a -c copy "movie-audio-delayed.mp4"
Make sure, that your ffmpeg build is not too old, newer than 2012 will suffice.

MP4 TO MP4 (MEDIUM)
ffmpeg -i input.mp4 -b 1000000 output.mp4

M2TS TO MP4
ffmpeg -i input.m2ts -vcodec libx264 -crf 20 -acodec ac3 -vf "yadif" output.mp4

MP4 TO WEBM (HIGH)
ffmpeg -i input.mp4 -aq 5 -ac 2 -qmax 25 -threads 2 output.webm

MP4 TO WEBM (MEDIUM)
ffmpeg -i input.mp4 -aq 5 -ac 2 -qmax 35 -threads 2 output.webm

MP4 TO OGV (HIGH)
ffmpeg -i input.mp4 -vcodec libtheora -acodec libvorbis -q:v 6 -q:a 5 output.ogv

MP4 TO OGV (MEDIUM)
ffmpeg -i input.mp4 -vcodec libtheora -acodec libvorbis -q:v 2 -q:a 4 output.ogv

ffmpeg -i video.mp4 -i audio.wav -c:v copy -c:a aac -strict experimental output.mp4

ffmpeg.exe -i Liar.Game.The.Final.Stage.2010.720p.BluRay.x264.DTS-WiKi.mkv -c:v h264_amf -crf 18 -vf subtitles="srt.srt" -c:a copy output.mp4

Comments

Popular posts from this blog

Setup mail server with ldap authentication in docker

How to allow non root user to execute hping command ?

Install VMware workstation 11 on Fedora 21 with kernel 3.17