#!/bin/sh
# ============================================
# Fichier : ffmpeg_exemples.sh
# ============================================
# 202108 : reduit_ffmpeg.sh
# les fichiers vidéos créés sur Android sont énormes,
# une simple conversion ffmpeg réduit la taille parfois de 80%
du -hsc *mp4
ls -1 *mp4 | sort > liste.txt
echo "$(date +%r) original $(du -hsc *mp4 | tail -1)"
while read a; do
echo "ffmpeg -i ${a} ${a}_ffmpeg_reduit.mp4"
done < liste.txt > go.sh
rm liste.txt
echo "UTILISER LE FICHIER go.sh créé à l'instant"
echo "$(date +%r) final $(du -hsc *ffmpeg*mp4 | tail -1)"
rename 's/\.mp4_ffmpeg/_ffmpeg/' *mp4
# 202108 : reduit_ffmpeg_x265.sh
# les fichiers vidéos créés sur Android sont énormes,
# une conversion ultra ffmpeg réduit la taille parfois de ...%
# ATTENTION : temps de conversion très très long ...
du -hsc *mp4
ls -1 *mp4 | sort > liste.txt
while read a; do
echo "ffmpeg -i ${a} -c:v libx265 -x265-params crf=25 -c:a libmp3lame ${a}_ffmpeg_x265.mkv"
done < liste.txt > go_x265.sh
rm liste.txt
# concaténer les mp3 d'un dossier en un éclair
# https://stackoverflow.com/questions/7333232/concatenate-two-mp4-files-using-ffmpeg
for i in $(seq 1 1 9); do
ln 0$i* $i
done
for i in $(seq 10 1 20); do
ln $i* $i
done
# pour 13 morceaux
ffmpeg -i 'concat:1|2|3|4|5|6|7|8|9|10|11|12|13' -codec copy tout.mp3
# encodage html5
IN=$1
OUT=$1
ffmpeg -i $IN -c:v libvpx -pass 1 -an -f rawvideo -y /dev/null # Generates ffmpeg2pass-0.log
ffmpeg -i $IN -c:v libvpx -pass 2 -f webm -b:v 400K -crf 10 -an -y $OUT.webm
# compression et lecture x265/hecv/h265
# voir fichier compression_video_ffmpeg_x265_hecv_hevc_h265.txt
SRC="DDC-Algérie [480p].mp4"
DST="DDC-Algérie [480p].x265.mkv"
time ffmpeg -i "$SRC" -c:v libx265 -x265-params crf=25 -c:a libmp3lame "$DST"
# extraire le son d'un MP4 téléchargé avec clipgrab
SRC=Twenty_one_pilots_Stressed_Out.mp4
ffmpeg -i "$SRC" -vn -c:a libmp3lame -ab 128k -ac 2 "$SRC.mp3"
MIEUX :
ffmpeg -i <votre fichier video>POUR AVOIR DES INFOS
ffmpeg -i <votre fichier video> -vn -acodec copy '(destination et) nom du fichier audio créé'.EXTENSION
# ffmpeg sur raspberry
https://www.raspberrypi.org/forums/viewtopic.php?t=44258&p=545741
1. "convertir" avec MP4Box
2. utiliser ffmpeg sur le fichier MP4Boxé
# combiner/merger deux vidéos côte à côte
# https://ffmpeg.org/ffmpeg-filters.html#Examples-51
ffmpeg -i 10h00.avi -i 11h00.avi -filter_complex "[0:v]setpts=PTS-STARTPTS, pad=iw*2:ih[bg]; [1:v]setpts=PTS-STARTPTS[fg]; [bg][fg]overlay=w" 10+11.avi
# OK côte à côte:
gauche=09h00.avi
droite=10h00.avi
ffmpeg -i $gauche -i $droite -filter_complex "[0:v]setpts=PTS-STARTPTS, pad=iw*2:ih[bg]; [1:v]setpts=PTS-STARTPTS[fg]; [bg][fg]overlay=w" -y ${gauche}+${droite}.avi
vlc ${gauche}+${droite}.avi
# OK superposés:
haut=11h00.avi
bas=12h05.avi
ffmpeg -i 10h00.avi -i 11h00.avi -filter_complex "[0:v]setpts=PTS-STARTPTS, pad=iw:ih*2[bg]; [1:v]setpts=PTS-STARTPTS[fg]; [bg][fg]overlay=0:h" -y 10+11dessus.avi ; vlc 10+11dessus.avi
ffmpeg -i ${haut} -i ${bas} -filter_complex "[0:v]setpts=PTS-STARTPTS, pad=iw:ih*2[bg]; [1:v]setpts=PTS-STARTPTS[fg]; [bg][fg]overlay=0:h" -y ${haut}sur${bas} ; vlc ${haut}sur${bas}
vlc ${haut}+${bas}.avi
# rendre image floue (blur)
ffmpeg -i 18h15.avi -vf "boxblur=4:1" 18h15_blur4.avi
#rotate video
http://superuser.com/questions/578321/how-to-flip-a-video-180%C2%B0-vertical-upside-down-with-ffmpeg
testé OK :
nice ffmpeg -i 10h55_39.h264 -an -vf "transpose=2,transpose=2,format=yuv420p" -codec:v libx264 10h55_39_ROTATE.avi
# encodage x264 avec croppage
time ffmpeg -i $a -an -vcodec libx264 -filter:v crop=190:120:30:180 -b:v $BITRATE ${a}.$BITRATE.mp4
# crop tailler image
# https://ffmpeg.org/ffmpeg-filters.html#Examples-27
Crop area with size 100x100 at position (12,34).
crop=100:100:12:34
Crop the central input area with size 100x100:
crop=100:100
Crop the central input area with size 2/3 of the input video:
crop=2/3*in_w:2/3*in_h
# crop ffmpeg version compilée 2014/2015
echo "---------------------pass 1 -----------------------"
ffmpeg -y -t 1800 -i $src -c:v libx264 -preset medium -b:v ${BITRATE} -pass 1 -filter:v "yadif,crop=in_w-2*16:in_h-2*16" -an -f mp4 /dev/null
echo "---------------------pass 2 -----------------------"
ffmpeg -t 1800 -i $src -c:v libx264 -preset medium -b:v ${BITRATE} -pass 2 -filter:v "yadif,crop=in_w-2*16:in_h-2*16" -c:a libfaac -b:a 128k ${src}.${BITRATE}.mp4
# essayer en une passe :
ffmpeg -i $a -an -vcodec mpeg4 -filter:v "crop=in_w-2*160:in_h-2*160" -b 5000k ${a}.avi
# encoder depuis h264 raspberry/raspivid vers avi lisible sur freebox (h264 également), TV samsung
ffmpeg -y -i 0325.mp4 -f avi -r 29.97 -vcodec libxvid -vtag XVID -vf scale=1080:576 -aspect 16:9 -maxrate 1800k -b 1500k -qmin 3 -qmax 5 -bufsize 4096 -mbd 2 -bf 2 -trellis 1 -flags +aic -cmp 2 -subcmp 2 -g 300 -acodec libmp3lame -ar 48000 -ab 128k -ac 2 0325.avi
# encoder pour Archos 2
mencoder "$1" -o "$1_ARCHOS2.avi" \
-ofps 15 -vf-add scale=160:128 \
-vf-add expand=160:128:-1:-1:1 \
-srate 44100 \
-ovc xvid \
-stereo 0 \
-xvidencopts bitrate=400:max_bframes=0:quant_type=h263:me_quality=0 \
-oac lavc -lavcopts acodec=mp2:abitrate=128 \
2>/dev/null
# screencast
# OK sur Lucid le 21 janvier 2013
ffmpeg -f x11grab -s wxga -r 25 -i :0.0 -sameq /tmp/out.mpg
# FFMPEG Progressbar shows the status of the conversion of media files with FFMPEG in a Web page.
http://freecode.com/projects/ffmpeg-progressbar
# encoder tous les enregistrements freebox lisibles en une ligne
find /n/f/Enregistrements -name "*.m2ts" -print0 | xargs -0 -i encoder_Nokia_HQ.sh "{}"
# OK aussi : find "$(pwd)" -name "*m2ts" -print0 | xargs -0 -i encoder_Nokia_HQ.sh {}
sh suite_nokia-iser.sh
# mkv-iser les fichiers du dossier courant
# en évitant les streams 2, 3 et 4 (subtitles Teletext par exemple)
ls *m2ts | xargs -i ffmpeg -i {} -map 0 -map -0:2 -map -0:3 -map -0:4 \
-c:v:0 libx264 -c:a:1 libfaac -ab 128k -ac 2 -async 1 -vsync 1 -s 720x540 -crf 22 -threads 0 -n {}.mkv
sh suite_mkv-iser.sh
# récupérer la sortie de ffmpeg
ffmpeg -i "video.m2ts" 2>1 > aaa
cat aaa | sed '/Input/,$p'
--> voir le script infos_multimedia.sh
# convertir une série de vidéos HD Freebox m2ts 1440x1080
# dans le dossier courant
# en mkv 720x540, en évitant les stream 0:2 (souvent dvb_teletext) et 0:3
size=720x540 ; find *m2ts -maxdepth 0 -print0 | xargs -0 -i ffmpeg -i {} -map 0 -map -0:2 -map -0:3 -map -0:4 \
-c:v:0 libx264 -c:a:1 libfaac -ab 128k -ac 2 -async 1 -vsync 1 -s $size -crf 22 -threads 0 {}.mkv
# concatener video et son
ffmpeg -i toutes_les_videos1.avi -r 25 -vcodec copy -i bande_son.mp3 -acodec copy -y \
-metadata title=\"$artiste - $titre\" \
-metadata transition=\"$typeTransition\" \
final.avi 2\>/dev/null
#########################################################################
# convertir un fichier .m2ts (HD Freebox)
ffmpeg -i "$SRC" -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -s 720x540 -crf 22 -threads 0 "$DEST"
=> pb : langue allemande
# OK : pour encoder avec audio français ( Stream #0:1[0x48](fra) ...)
ffmpeg -i "$SRC" -map 0 -c:v libx264 -c:a:1 libfaac -ab 128k -ac 2 -async 1 -vsync 1 \
-s 720x540 -crf 22 -threads 0 -y "$SRC.x264.mp4"
=> curieusement, le mp4 final contient les deux audio, idem si extension mkv
#####################################################
Bonne nouvelle : les deux fichiers sont lisibles par la freebox6,
qui reconnaît également les deux pistes audio !
#####################################################
car
ffmpeg -i *m2ts
Stream #0:0[0x43](qaa): Audio: aac ([15][0][0][0] / 0x000F), 48000 Hz, stereo, s16, 72 kb/s
Stream #0:1[0x48](fra): Audio: aac ([15][0][0][0] / 0x000F), 48000 Hz, stereo, s16, 133 kb/s
Stream #0:2[0x49]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 1440x1080 [SAR 4:3 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
man ffmpeg :
For example
ffmpeg -i INPUT -map 0 -c:v libx264 -c:a copy OUTPUT
encodes all video streams with libx264 and copies all audio streams.
For each stream, the last matching "c" option is applied, so
ffmpeg -i INPUT -map 0 -c copy -c:v:1 libx264 -c:a:137 libvorbis OUTPUT
will copy all the streams except the second video, which will be encoded with libx264, and the 138th audio,
which will be encoded with libvorbis.
######################################################
To select all video and the third audio stream from an input file:
ffmpeg -i INPUT -map 0:v -map 0:a:2 OUTPUT
######################################################
Flux intraitable (erreur dvb pour le 0:2) :
Stream #0:0[0x44]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 1440x1080 [SAR 4:3 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1[0x45]: Audio: aac ([15][0][0][0] / 0x000F), 48000 Hz, stereo, s16, 116 kb/s
Stream #0:2[0x46](fra): Subtitle: dvb_teletext ([6][0][0][0] / 0x0006)
utiliser -map -0:2 pour ne pas traiter ce flux :
ffmpeg -i "$1" -map 0 -map -0:2 -c:v:0 libx264 -c:a:1 libfaac -ab 128k -ac 2 -async 1 -vsync 1 \
-s 720x540 -crf 22 -threads 0 "$DST"
# pour éviter les problèmes de synchronisation son/vidéo dans ffmpeg
# utiliser -async 1 -vsync 1
-async 1 -vsync 1
#####################################################
# encodage haute qualité pour Nokia 2 pass
#####################################################
# DDC-Occident.mpg = 480x576, 50 img/sec
# a tester encore
# remarque : on peut changer le bitrate dans la deuxième opération, cela fonctionne
# essayer vcodec libxvid
# conserver résultats pass1
SRC=DDC-Occident.mpg
DST=DDC-Occident.tester_NOKIA.$bitrate.mp4
# deinterlace=-deinterlace
preset=fast
bitrate=1000k
size=480x288
vcodec=mpeg4
acodec=libmp3lame
ffmpeg -i $SRC -pass 1 -vcodec $vcodec -preset $preset -b $bitrate -s $size -r 25 -f mp4 -an -y /dev/null
ffmpeg -i $SRC -pass 2 -acodec $acodec -ab 128k \
-ac 2 -vcodec $vcodec -preset $preset -b $bitrate -s $size -r 25 -y $DST
=> pas terrible en fait
#############################
# BEAUCOUP MIEUX (a verifier) :
#############################
# http://ffmpeg.org/faq.html#SEC23
# 3.12 Which are good parameters for encoding high quality MPEG-1/MPEG-2?
# -mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -g 300 -pass 1/2',
# things to try: '-bf 2', '-flags qprd', '-flags mv0', '-flags skiprd'.
Source =
Seems stream 0 codec frame rate differs from container frame rate: 50.00 (50/1) -> 25.00 (50/2)
Input #0, mpeg, from 'CDM_finale_200m_argent_France.mpg':
Duration: 00:07:04.98, start: 15230.536967, bitrate: 3048 kb/s
Stream #0.0[0x1e0]: Video: mpeg2video (Main), yuv420p, 480x576 [PAR 32:15 DAR 16:9], 15000 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0.1[0x1c0]: Audio: mp2, 48000 Hz, stereo, s16, 192 kb/s
# fonctionne :
DST=$1.$bitrate.NOKIA.1.mp4
ffmpeg -i $SRC -vcodec $vcodec -s $size -preset $preset -b $bitrate -r 25 -f mp4 -acodec $acodec -ab 128k \
-mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -g 300 -y $DST
cp $DST /media/CDF2-6BE2
# Image noire sur Nokia, puis lecture impossible :
DST=$1.$bitrate.NOKIA.2.mp4
ffmpeg -i $SRC -vcodec $vcodec -s $size -preset $preset -b $bitrate -r 25 -f mp4 -acodec $acodec -ab 128k \
-mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -g 300 -bf 2 -y $DST
cp $DST /media/CDF2-6BE2
alarme_mp3.sh
# ne fonctionne pas
DST=$1.$bitrate.NOKIA.3.mp4
ffmpeg -i $SRC -vcodec $vcodec -s $size -preset $preset -b $bitrate -r 25 -f mp4 -acodec $acodec -ab 128k \
-mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -g 300 -flags qprd -y $DST
cp $DST /media/CDF2-6BE2
alarme_mp3.sh
#####################################################
# conversion 3gp pour Samsung L770
#####################################################
/opt/MIKSOFT/MobileMediaConverter/lib/ffmpeg -y -i ~/ruquier.wmv -f 3gp \
-vcodec h263 -s qcif -r 15 -b 100k -acodec libfaac -ac 2 -ar 32000 -ab 64k \
-map_meta_data ~/ruquier.3gp:~/ruquier.wmv ~/ruquier.3gp
#####################################################
# ffmpeg conversion divx
#####################################################
ffmpeg -i fichier.avi -f mp4 -vcodec libxvid -b 1000k -s 640x480 -acodec libmp3lame -ab 128k -ac 2 -y fichier.mp4
si erreur libxvid pixel ratio, ajouter -aspect ...
source="Jump_global_mix.mp4"
bitrate=3000k ; size=1280x720 ; aspect=1280:720 ; ffmpeg -i "$source" -vcodec libxvid -aspect $aspect -b $bitrate -s $size -acodec libmp3lame -ab 128k -ac 2 -y $bitrate.$size.mp4
bitrate=2000k ; size=640x360 ; aspect=1280:720 ; ffmpeg -i "$source" -vcodec libxvid -aspect $aspect -b $bitrate -s $size -acodec libmp3lame -ab 128k -ac 2 -y $bitrate.$size.mp4
#####################################################
# Insérer métadonnées metadata dans une vidéo ffmpeg
# (commentaire)
#####################################################
source=input.avi
dest=output.avi
ffmpeg -i $source -metadata title="Moonshine" \
-metadata author="Moonshine" \
-metadata copyright="2009" -metadata comment="foo" \
-acodec copy -vcodec copy $dest
Voir résultat :
ffmpeg -i $dest 2>&1 | sed -n '/Metadata/,$p'
ffmpeg -i $dest 2>&1 | sed -n '/Metadata/,/Duration/p'
#####################################################
# à commenter
#####################################################
#!/bin/bash
#
# plusieurs exemples d'encodage avec ffmpeg
#
[ "x$1" = "x" ] && geany $0 && exit 0
[ "x$1" = "xedit" ] && geany $0 && exit 0
[ "x$1" = "xcopy" ] && cp $0 . && exit 0
IFS=$'\n'
outputdir=~/Vidéos/convertir_flv_Nokia/$(date +%Y%M%d_%H%M%S)
mkdir $outputdir || echo Impossible de créer le dossier $outputdir
mkdir $outputdir || echo FIN
cd fichiers_a_convertir
for source in *
do
banner c parti
dest="$outputdir/${source%.*}.3gp"
ffmpeg -y -i "$source" -vcodec h263 -s 352x288 -r 15 -b 800k -acodec libfaac -ac 1 -ar 32000 -ab 64k -f 3gp -map_meta_data "$dest":"$source" "$dest"
cp "$dest" /media/CDF2-6BE2/_NK_videos/_dernieres_conversions_
echo $(date) FIN >> $LOGFILE
echo >> $LOGFILE
done
#!/bin/bash
# encodage_video_pour_NOKIA.sh
[ "$1" = "edit" ] && geany $0 && exit 0
[ "$1" = "copy" ] && cp $0 . && exit 0
exit 1
IFS=$'\n'
LOGFILE=journal_NOKIA.log
NBTHREADS=0
BITRATE=1500k
VITESSE=slow
for source in *mpg
do
CROP=$(echo $i | sed 's/__/\//' | sed 's/.vob//' | cut -d'/' -f2)
# echo CROP=$CROP
banner $CROP
banner c parti
rndm=$RANDOM
#ffmpeg -y -i "$source" -vcodec mpeg4 -s 480x320 -r 25 -b 700k -acodec libfaac -ac 2 -ar 44100 -ab 128k -threads $NBTHREADS -f mp4 -map_meta_data ffmpeg${rndm}.mp4 ffmpeg${rndm}.mp4
ffmpeg -y -i "$source" -vcodec mpeg4 -s 640x400 -r 25 -b 700k -acodec libfaac -ac 2 -ar 44100 -ab 128k -async 1 -threads $NBTHREADS -f mp4 -map_meta_data ffmpeg${rndm}.mp4 ffmpeg${rndm}.mp4
mv ffmpeg${rndm}.mp4 "${source}.NOKIA.mp4"
#rndm=$RANDOM
#ffmpeg -y -i "$source" -vcodec mpeg4 -s 640x480 -r 25 -b 1000k -mbd rd -flags +mv4 -trellis 2 -cmp 2 -subcmp 2 -g 300 -bf 2 -acodec libfaac -ac 2 -ar 44100 -ab 128k -threads 4 -f mp4 -map_meta_data result/ffmpeg${rndm}.mp4 result/ffmpeg${rndm}.mp4
#mv result/ffmpeg${rndm}.mp4 "result/NK.${source}.mp4"
#echo "$(date) conversion finie" > "result/NK.${source}.log"
echo $(date) FIN >> $LOGFILE
echo >> $LOGFILE
done
exit 1
#==================================================
#!/bin/bash
# encodage_video_pour_NOKIA.sh
[ "$1" = "edit" ] && geany $0 && exit 0
[ "$1" = "copy" ] && cp $0 . && exit 0
IFS=$'\n'
LOGFILE=journal_NOKIA.log
NBTHREADS=0
BITRATE=1500k
VITESSE=slow
source=~/canal.flv
dest=~/canal.3gp
ffmpeg -y -i ~/canal.flv -vcodec h263 -s 352x288 -r 15 -b 800k -acodec libfaac -ac 2 -ar 32000 -ab 64k -f 3gp -map_meta_data ~/canal.3gp:~/canal.flv ~/canal.3gp
exit 1
for source in *mpg
do
banner c parti
echo $(date) FIN >> $LOGFILE
echo >> $LOGFILE
done
#==================================================
# ============================================
# Fichier : encodage_ffmpeg_x264_2passes.sh
# But : profiter d'un des meilleurs codecs
# pour réduire taille vidéos (x264)
# Date : novembre 2010
# Version : 1.02
# ============================================
[ "$1" = "edit" ] && geany $0 && exit 0
[ "$1" = "copy" ] && cp $0 . && exit 0
IFS=$'\n'
LOGFILE=journal.log
NBTHREADS=3
BITRATE=800k
SOURCE="Empreintes, portrait de Bertrand Tavernier.mpg"
DEST="Empreintes, portrait de Bertrand Tavernier.800k.1pass.x264.mp4"
CROP=480:560:0:0
# ==================
# Bandes noires
# ==================
# Exemple : CROP=480:560:0:8
# utiliser ceci pour couper les bandes noires :
# mplayer -v -vf cropdetect video.mpg
# ffplay -vf cropdetect video.mpg
# ==================
# Pb synchro audio
# ==================
# utiliser -async 1 pour les .mpg freebox pc pour corriger décalage audio
# ==================
# Encodage 1 passe
# ==================
# ffmpeg -i $SOURCE -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre slow -crf 22 -threads $NBTHREADS $DEST
ffmpeg -i $SOURCE -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre fast -crf 22 -threads $NBTHREADS $DEST
# ==================
# Encodage 2 passes
# ==================
echo > $LOGFILE
echo "=========================" >> $LOGFILE
echo "===== Première passe ====="
echo AVANT : $(date) >> $LOGFILE
ffmpeg -i $SOURCE -pass 1 -passlogfile passlofile.log -vcodec libx264 -vpre fast_firstpass -vf crop=$CROP -b $BITRATE -bt $BITRATE -threads 4 -f rawvideo -an -y /dev/null
echo MILIEU : $(date) >> $LOGFILE
echo "===== Seconde passe ====="
ffmpeg -i $SOURCE -pass 2 -passlogfile passlofile.log -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre fast -vf crop=$CROP -b $BITRATE -bt $BITRATE -threads $NBTHREADS $DEST
echo APRES : $(date) >> $LOGFILE
echo "=========================" >> $LOGFILE
ls -l >> $LOGFILE
echo "=========================" >> $LOGFILE
cat $LOGFILE | xsel -b -i
pensebete_mailauto.sh
# ./lancer_autre_encodage.sh
# à lancer avec sudo
# shutdown -h 1
#==================================================
# ============================================
# Fichier : encodage_ffmpeg_x264_1500k_slow.sh
# But : profiter d'un des meilleurs codecs
# pour réduire taille vidéos (x264)
# Date : janvier 2011
# ============================================
# le nom du fichier contient les paramètres de rognage (crop) :
# exemple
# 1994 - Bretagne, Eurotunnel, Moussa, Tom__688:560:16:4.vob
# => -vf crop=688:560:16:4
#
# cropper .h264 raspivid
CROP=175:50:304:276 # le 14 avril (raspivid -ss, shutter spedd)
CROP=1540:$((644-272)):0:272 # le 14 avril (raspivid -ss, shutter spedd)
CROP=w:h:x:y
ls -1 *.h264 2>/dev/null |
xargs -i nice ffmpeg -i {} -an \
-vcodec mpeg4 -filter:v crop=$CROP -b:v 2000k {}.avi 2>/dev/null
IFS=$'\n'
LOGFILE=journal.log
NBTHREADS=0
BITRATE=1500k
VITESSE=slow
for i in *mpg
do
CROP=$(echo $i | sed 's/__/\//' | sed 's/.vob//' | cut -d'/' -f2)
# echo CROP=$CROP
banner $CROP
echo $(date) DEBUT ffmpeg -i $i -acodec libfaac -ab 128k -ac 2 -async 1 -vcodec libx264 -vpre $VITESSE -vf crop=$CROP -b $BITRATE -threads $NBTHREADS -y ${i}.$BITRATE.x264.mp4 >> $LOGFILE
banner c parti
ffmpeg -i $i -acodec libfaac -ab 128k -ac 2 -async 1 -vcodec libx264 -vpre $VITESSE -vf crop=$CROP -b $BITRATE -threads $NBTHREADS -y ${i}.$BITRATE.x264.mp4 >> $LOGFILE
echo $(date) FIN >> $LOGFILE
echo >> $LOGFILE
done
for i in *mpg
do
CROP=$(echo $i | sed 's/__/\//' | sed 's/.mpg//' | cut -d'/' -f2)
# echo CROP=$CROP
banner $CROP
echo $(date) DEBUT ffmpeg -i $i -acodec libfaac -ab 128k -ac 2 -async 1 -vcodec libx264 -vpre $VITESSE -vf crop=$CROP -b $BITRATE -threads $NBTHREADS -y ${i}.$BITRATE.x264.mp4 >> $LOGFILE
banner c parti
ffmpeg -i $i -acodec libfaac -ab 128k -ac 2 -async 1 -vcodec libx264 -vpre $VITESSE -vf crop=$CROP -b $BITRATE -threads $NBTHREADS -y ${i}.$BITRATE.x264.mp4 >> $LOGFILE
echo $(date) FIN >> $LOGFILE
echo >> $LOGFILE
done
#####################
Using FFmpeg and x264
#####################
http://ubuntuforums.org/showthread.php?t=786095
The easiest method for high quality video encoding is by using the libx264 presets. See x264 --fullhelp for more info on these options.
One-pass CRF (Constant Rate Factor) using the slow preset. One-pass CRF is good for general encoding and is what I use most often. Adjust -crf to change the quality. Lower numbers mean higher quality and a larger output file size. A sane range is 18 to 28.
Code:
ffmpeg -i input -acodec libfaac -aq 100 -vcodec libx264 -preset slow -crf 22 \
-threads 0 output.mp4
One-pass CRF (Constant Rate Factor) using the medium preset, animation tuning, baseline profile, and level 3.0:
Code:
ffmpeg -i input -acodec libfaac -aq 100 -vcodec libx264 -preset medium \
-tune animation -profile baseline -level 3.0 -crf 20 -threads 0 output.mp4
Two-Pass encode using the fast preset. Two-pass encoding is usually used when you want a specific output file size.
Code:
ffmpeg -i input -pass 1 -vcodec libx264 -preset fast -b 512k -threads 0 \
-f mp4 -an -y /dev/null && ffmpeg -i input.avi -pass 2 -acodec libfaac -ab 128k \
-ac 2 -vcodec libx264 -preset fast -b 512k -threads 0 output.mp4
# Si ça peut te dépanner, voici la ligne de commande que j'utilise pour
# convertir mes avi en mpeg (sans altération de qualité):
#
# ffmpeg -i source.avi -target pal-dvd -aspect 4:3 -sameq cible.mpg
#
# La différence de taille (entre avi et mpg) est de 4 à 1 (et même plus).
#############################
# Convertir audio .m4a en .mp3
# en conservant les données meta (auteur, titre, ...)
#############################
ffmpeg -i file.m4a -acodec libmp3lame -ac 2 -ar 44100 -ab 192k -map_meta_data file.mp3 file.mp3
#############################
# Créer animation image fixe
#############################
Animation de 3 secondes d\'une image fixe :
ffmpeg -loop_input -vframes 75 -r 25 -i source.jpg -r 25 -b 500k -vcodec libxvid -s 640x480 -y animation_image_fixe.avi
#####################################################
# Images individuelles
#####################################################
For extracting images from a video:
ffmpeg -i foo.avi -r 1 -s WxH -f image2 foo-%03d.jpg
This will extract one video frame per second from the video and will output them in files named foo-001.jpg, foo-002.jpg, etc.
Images will be rescaled to fit the new WxH values.
If you want to extract just a limited number of frames, you can use the above command in combination with the -vframes or -t
option, or in combination with -ss to start extracting from a certain point in time.
# For creating a video from many images:
ffmpeg -f image2 -i foo-%03d.jpg -r 12 -s WxH foo.avi
# mencoder le fait également :
# créer une vidéo depuis une série d'images
# http://electron.mit.edu/~gsteele/ffmpeg/
mencoder "mf://test*.jpg" -mf fps=1 -o test.avi -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=800
#####################################################
# Ajouter des sous-titres avec ffmpeg
#####################################################
Apparemment, c est impossible, utiliser mencoder
#####################################################
# Afficher bitrate avi avec ffmpeg
#####################################################
find . -iname '*avi' | sort > liste.m3u
rm durée_des_films_avi.txt
rm duration.tmp.txt
echo Nombre de films trouvés : `wc -l < liste.m3u`
while read line
do
ffmpeg -i "$line" 2>duration.tmp.txt
echo $line >> durée_des_films_avi.txt
grep Duration duration.tmp.txt >> durée_des_films_avi.txt
echo >> durée_des_films_avi.txt
echo $line
grep Stream duration.tmp.txt
echo =========================
done < liste.m3u
rm duration.tmp.txt
cat durée_des_films_avi.txt
rm liste.m3u
Encodage deux passes x264 (non testé personnellement) :
#!/bin/sh
ffmpeg -i $1 -y -an -pass 1 -vcodec libx264 -threads 4 -b 1024kbps -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me epzs -subq 1 -trellis 0 -refs 1 -bf 3 -b_strategy 1 -coder 1 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 $2
ffmpeg -i $1 -y -acodec libfaac -ab 128k -pass 2 -vcodec libx264 -threads 4 -b 1024kbps -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -flags2 +mixed_refs -me umh -subq 5 -trellis 1 -refs 5 -bf 3 -b_strategy 1 -coder 1 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 $2
# conversion pour lecture sur Nokia
ffmpeg -y -i "Arte - La vie de Brian - 05-05-2011 21h02 01h07 (125).m2ts" -vcodec mpeg4 -s 640x400 -r 25 -b 900k -acodec libmp3lame -ac 2 -ab 128k -async 1 -vsync 1 -f mp4 output.mp4
# conversion flv vers mp3
IFS=$'\n' ; for i in $(ls -1 *.flv) ; do ffmpeg -i "$i" -acodec libmp3lame -ac 2 -ab 128k -map_metadata 0:0 "$i".mp3 ; banner suite ; done
##################################
# barre de progression avec ffmpeg
##################################
# s'inspirer du fichier ci-dessous
# source : http://forum.ubuntu-fr.org/viewtopic.php?pid=1622378#p1622378
#!/bin/bash
QUANTITE="${#@}"
COMPTEUR=0
for A in "$@"
do
((COMPTEUR ++))
duree=`mplayer -identify -vo null -ao null -frames 0 "$A" 2>/dev/null | sed -ne '/^ID_LENGTH/s/.*=\([0-9]*\).*/\1/p'`
nbframe_per_sec=`mplayer -identify -vo null -ao null -frames 0 "$A" 2>/dev/null | sed -ne '/^ID_VIDEO_FPS/s/.*=\([0-9]*\).*/\1/p'`
nbframes=$((duree*nbframe_per_sec))
METTRE_LA_LIGNE_DE_CONVERSION_FFMPEG_ICI \
2>&1 | gawk -vRS='\r' '$1 ~ /frame|size/ {gsub(/.*time=/,""); pourcent=$1*100/'$duree' ; if ( pourcent>99 && '$COMPTEUR'!='$QUANTITE' ) pourcent=99 ; print "#['$COMPTEUR'/'$QUANTITE'] Conversion du fichier : '"$A"'\n" pourcent; fflush();}'
done | zenity --progress --auto-close