Skip to main content

Conversion FFMPEG

Ressources / explications : https://github.com/leandromoreira/digital_video_introduction

https://amiaopensource.github.io/ffmprovisr/

Rassembler plusieurs vidéos de type MTS : http://stackoverflow.com/questions/3554787/using-ffmpeg-to-join-two-mts-files-together#31837321 http://stackoverflow.com/questions/5672687/merge-join-images-video-files-together-using-mencoder-or-ffmpeg

https://trac.ffmpeg.org/wiki/Concatenate

https://www.youtube.com/watch?v=hElDsyuAQDA https://www.youtube.com/playlist?list=PLx32r1KYmsKnmeH2enbDARTj_cu_9MP5E

Montage video / Editing

Davinci Resolve with Linux : Prerequisites : https://www.linuxuprising.com/2018/06/how-to-install-davinci-resolve-15-in.html

https://www.reddit.com/r/linux/comments/9cuexb/anyone_using_davinci_resolve_for_video_ediiting/ https://forum.level1techs.com/t/video-editing-codecs-in-ubuntu-18-04-with-davinci-resolve-15/129632/3

https://trac.ffmpeg.org/wiki/Concatenate

The "Protocol" Concat

.\ffmpeg.exe -i "concat:00000.MTS|00001.MTS|00002.MTS" test.mp4

.\ffmpeg.exe -i "concat:00002.MTS|00003.MTS" essai.mp4

Gci . -Include *.mts -Recurse | select name
$Vidz = (Gci . -Include *.mts -Recurse).Name -join '|'

.\ffmpeg.exe -i "concat:$Vidz" essai.mp4

The "Demuxer" Concat -- Use this one !!!!

cd /home/wes/Documents/Hockey-M18-BB/2023-11-28.CobraNord
#ls -I"match*" >> match_complet.txt
#find $PWD -type f -iname "mvi*" | sort > match_complet.txt
for i in *.MP4; do echo "file '$i'";done > match_complet.txt
ffmpeg -f concat -i match_complet.txt -c copy MatchComplet.mp4
Gci . -Include *.mts -Recurse | %{"file '$($_.name)'"} | Out-File .\ListeVideo.txt -Force -Encoding default
Ise .\ListeVideo.txt
psedit .\ListeVideo.txt

# .\ffmpeg.exe -f concat -i .\ListeVideo.txt -c copy MatchComplet.mp4
. 'C:\Tools\Video tools\ffmpeg-20161104-b4e9252-win64-static\bin\ffmpeg.exe' -f concat -i .\ListeVideo.txt -c copy MatchComplet.mts
. 'C:\Tools\Video tools\ffmpeg-20181016-b2adc31-win64-static\bin\ffmpeg.exe' -f concat -i .\ListeVideo.txt -c copy MatchComplet.mpg

Encode H264

.\ffmpeg.exe -i "00003.MTS" -f mp4 -c:v libx264 -c:a copy -preset medium -crf 22 EssaiH264.mp4

. 'C:\Tools\Video tools\ffmpeg-20181016-b2adc31-win64-static\bin\ffmpeg.exe' -i 'M2U00175.MPG' -f mp4 -c:v copy -c:a copy -ss 0 -t 30 Essai_Original.mp4 . 'C:\Tools\Video tools\ffmpeg-20181016-b2adc31-win64-static\bin\ffmpeg.exe' -i 'M2U00175.MPG' -f mp4 -c:v libx264 -c:a copy -profile:v high -preset slow -crf 22 -ss 0 -t 30 Essai.mp4 . 'C:\Tools\Video tools\ffmpeg-20181016-b2adc31-win64-static\bin\ffmpeg.exe' -i 'M2U00175.MPG' -f mp4 -c:v libx264 -c:a aac -b:96k -profile:v high -preset slow -crf 22 -ss 0 -t 30 Essai_2.mp4

ffmpeg -i MatchComplet.mp4 -f mp4 -c:v libx264 -c:a aac -b:a 96K -profile:v high -preset slow -crf 22 MatchComplet_encoded.mp4

To deinterlace the video, use the filter yadif - https://ffmpeg.org/ffmpeg-filters.html

. 'C:\Tools\Video tools\ffmpeg-20181016-b2adc31-win64-static\bin\ffmpeg.exe' -i 'M2U00175.MPG' -f mp4 -c:v libx264 -c:a copy -profile:v high -preset slow -crf 22 -ss 0 -t 30 -vf yadif Essai_deinterlace.mp4

To add some texts, use the filter drawtext

. 'C:\Tools\Video tools\ffmpeg-20181016-b2adc31-win64-static\bin\ffmpeg.exe' -i 'M2U00175.MPG' -f mp4 -c:v libx264 -c:a copy -profile:v high -preset slow -crf 22 -ss 0 -t 30 -vf drawtext="text='2018-10-14 - Express : 1 / Laval Est : 4'" Essai_test.mp4 . 'C:\Tools\Video tools\ffmpeg-20181016-b2adc31-win64-static\bin\ffmpeg.exe' -i 'M2U00175.MPG' -f mp4 -c:v libx264 -c:a copy -profile:v high -preset slow -crf 22 -ss 0 -t 30 -vf drawtext="fontfile=\Windows\Fonts\mononoki-Regular.ttf:text='2018-10-14 - Express : 1 / Laval Est : 4':fontsize=30:fontcolor=red:x=10:y=10'" Essai_text.mp4

. 'C:\Tools\Video tools\ffmpeg-20181016-b2adc31-win64-static\bin\ffmpeg.exe' -i 'M2U00175.MPG' -f mp4 -c:v libx264 -c:a copy -profile:v high -preset slow -crf 22 -ss 0 -t 15 -vf yadif="parity=tff",drawtext="fontfile=mononoki-Regular.ttf:text='2018-10-14 - Express : 1 / Laval Est : 4':x=(w-text_w).10:y=(h-text_h).90:fontsize=30:fontcolor=red",fade=t=in:st=0:d=1,fade=t=out:st=4:d=1 Essai_text.mp4

drawtext="fontfile=/Windows/Fonts/Corbelb.ttf:text='Fiona':fontsize=40:fontcolor=yellow:x=1321:y=417"

À partir de l’adresse https://superuser.com/questions/649412/ffmpeg-x264-encode-settings

Sharpen video - https://ffmpeg.org/ffmpeg-filters.html#toc-unsharp-1

Unsharp

. 'C:\Tools\Video tools\ffmpeg-20181016-b2adc31-win64-static\bin\ffmpeg.exe' -i 'M2U00175.MPG' -f mp4 -c:v libx264 -c:a copy -profile:v high -preset slow -crf 22 -ss 0 -t 30 -vf "unsharp" Essai_filters.mp4 . 'C:\Tools\Video tools\ffmpeg-20181016-b2adc31-win64-static\bin\ffmpeg.exe' -ss 0 -i 'M2U00175.MPG' -f mp4 -c:v libx264 -c:a copy -profile:v high -preset slow -crf 22 -t 30 -vf "unsharp=3:3,yadif" Essai_filters.mp4 -y

Multiple filters must be separated by a comma (,)

-vf yadif,drawtext="text='mysentence':fontsize=20"

Final

. 'C:\Tools\Video tools\ffmpeg-20181016-b2adc31-win64-static\bin\ffmpeg.exe' -i 'M2U00175.MPG' -f mp4 -c:v libx264 -c:a copy -profile:v high -preset slow -crf 22 -ss 0 -t 30 -vf yadif="parity=tff",drawtext="fontfile=\Windows\Fonts\mononoki-Regular.ttf:text='2018-10-14 - Express : 1 / Laval Est : 4 :fontsize=30:fontcolor=red:x=10:y=10'" Essai_final.mp4

<# encode in Handbrake

Variable bitrate 1000 - 2 pass

Variable bitrate 3621 - 2 pass, 720p Audio passthru

Filters

Detelecine : Default Decomb : Default

Audio

AAC (avcodec) - bitrate 96 - mixdown stereo

#>

Calcul du bitrate : - Utiliser 0.092 Bits/(pixel*frame) - Framerate : 59,94

Pour l'encodage mHD dans Handbrake : https://tutox264.wordpress.com/

Profile à créer dans Handbrake : ref=6:subq=7:trellis=0:bframes=3:b-adapt=2:direct=auto:me=umh:merange=16:analyse=all:open-gop=0:rc-lookahead=50:level=4.1:no-fast-pskip=1:no-mixed-refs=0:no-weightb=0:no-mbtree=0

Pour la largeur(width) 812 - test que j'ai fait Pour du HD 720p : 1280 de largeur (width) Pour du 1080p : 1920 de largeur (width)

Déclinaison de la qualité en fonction du CRF

https://forum.ubuntu-fr.org/viewtopic.php?pid=15341951#p15341951

Autre méthode, avec le CRF (Constant Rate Factor)

https://wiki.t411.li/doku.php/ripper-transformer/encoder_en_x264_avec_handbrake

Pour faire un “HD léger”, sélectionnez un CRF 25 en 1080p, un CRF 23 en 720p, et un CRF 21 en SD. A taille équivalente, un fichier de définition plus faible sera généralement de meilleure qualité qu'un CRF supérieur (e.g. un 720p CRF 21 sera meilleur qu'un 1080p CRF26 sur un écran HD).

Sommaire: Width : 1280 Anamorphic : Loose Modulus : 4

Decomb: Bob X264 Same as source, variable bitrate Constant Quality : 23 X264 preset : Slower X264 tune : none H264 Profile : High H264 Level : Auto

Fade in and fade out automatic

https://video.stackexchange.com/questions/19867/how-to-fade-in-out-a-video-audio-clip-with-unknown-duration