Last active
April 19, 2024 07:38
-
-
Save ZiTAL/2c72a36e2523ff0a54c45adc477d3599 to your computer and use it in GitHub Desktop.
ffmpeg examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/bash | |
# resize and crop | |
# ffmpeg: 1440x1072 -> 1452x1080 -> 1440x1080 rockchip h264_rkmpp | |
ffmpeg-rockchip -i input.mp4 -b:v 2472k -vcodec h264_rkmpp -s 1452x1080 -r 30 -g 60 -b:a 160k -ar 44100 -threads 4 tmp.mp4 | |
ffmpeg-rockchip -i tmp.mp4 -b:v 2472k -vcodec h264_rkmpp -s 1440x1080 -r 30 -g 60 -filter:v \"crop=1440:1080:6:0\" -aspect 4:3 -acodec copy -threads 4 output.mp4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/bash | |
# ffmpeg: encode using nvidia gpu nvenc | |
ffmpeg \ | |
-i input.mkv \ # input | |
- map 0:1 # choose video track | |
- map 0:6 # choose audio track | |
-vcodec h264_nvenc \ # encode driver | |
-b:v 8192k \ # video bit rate | |
-r 30 \ # fps | |
-acodec copy \ # audio codec | |
-map_metadata -1 \ # remove metadata | |
-map_chapters -1 \ # remove chapters | |
-threads 4 \ # use 4 cores | |
output.mp4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# audio originala hartu | |
ffmpeg -i 1.mp4 -vn a.m4v | |
# youtube-tik jeitsi | |
youtube-dl https://www.youtube.com/watch?v=vmGPIIHxWqY | |
# zatia hartu | |
ffmpeg -i Huevazo\ al\ alcalde\ de\ Vitoria-Gasteiz-vmGPIIHxWqY.mp4 -ss 00:00:48.000 -t 00:00:03.000 2.mp4 | |
# bideoa 480x480 bihurtu, 640x480 zan, beraz (640-480)/ 2 = 80, x-a 80tik hasiko da eta y 0-tik | |
ffmpeg -i 2.mp4 -filter:v "crop=480:480:80:0" -c:a copy 22.mp4 | |
mv 22.mp4 2.mp4 | |
# 1.mp4-eko metadatuekin 2.mp4 enkodeatu eta 22.mp4 sortu | |
ffmpeg -i 1.mp4 -i 2.mp4 -map 1 -c copy -map_metadata 0 -map_metadata:s:v 0:s:v -map_metadata:s:a 0:s:a 22.mp4 | |
mv 22.mp4 2.mp4 | |
# mpeg2-ra pasatu | |
ffmpeg -i 1.mp4 -qscale 0 1.mpg | |
ffmpeg -i 2.mp4 -qscale 0 2.mpg | |
# audioa kendu | |
ffmpeg -i 1.mpg -an 01.mpg | |
ffmpeg -i 2.mpg -an 02.mpg | |
# konkatenatu eta mp4-ra enkodeatu | |
cat 01.mpg 02.mpg | ffmpeg -f mpeg -i - 3.mp4 | |
# audioa sartu | |
ffmpeg -i 3.mp4 -i a.m4a output.mp4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# video to gif | |
ffmpeg -i input.mp4 -vf fps=10,scale=320:-1:flags=lanczos,palettegen palette.png | |
ffmpeg -i input.mp4 -i palette.png -filter_complex "fps=10,scale=320:-1:flags=lanczos[x];[x][1:v]paletteuse" output.gif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ffmpeg: increase brightness | |
ffmpeg -i input.mp4 -vf eq=brightness=0.08 -c:a copy output.mp4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ffmpeg: mix audio | |
ffmpeg -y -i input01.mp3 -i input02.mp3 -filter_complex "[0:a][1:a] amix=inputs=2:duration=longest[a]" -map "[a]" output.mp3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# concat videos | |
$ cat a.txt | |
file '001.mp4' | |
file '002.mp4' | |
file '003.mp4' | |
$ ffmpeg -f concat -safe 0 -i a.txt a.mp4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ffmpeg: record desktop + pulseaudio | |
ffmpeg -f pulse -ac 2 -i 0 -f x11grab -s 1280x800 -i :0.0 sample.mpg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# gif to video | |
ffmpeg -i animated.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" video.mp4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# bash: ffmpeg "image + audio to video" mobile compatible | |
ffmpeg -loop 1 -i logo.png -i audio.mp3 -pix_fmt yuv420p -shortest output.mp4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ffmpeg: add black border to video | |
# original video 480x196 -> to 16:9 480x270 -> 270-196 = 74 -> 74 / 2 = 37 | |
# add 74 pixels, 37 from top and 37 from bottom | |
ffmpeg -i input.avi -pix_fmt yuv420p -filter_complex "[0]pad=h=74+ih:y=37:color=black" output.mp4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ffmpeg: convert vertival video into horizontal adding black | |
ffmpeg -i input.mp4 -vf "scale=1920:-2:flags=lanczos, scale=480:848, pad=1920:1080:(ow-iw)/2:(oh-ih)/2:black" output.mp4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# bash: ffmpeg batch conversion | |
# ./convert.sh /home/zital/Music | |
INPUT_DIR=$1 | |
INPUT_EXTENSION=mp2 | |
OUTPUT_EXTENSION=mp3 | |
EXTRA=" -vn -ab 256k -ar 48000 -ac 2 " | |
FILES=`find "$INPUT_DIR" | grep $INPUT_EXTENSION` | |
SAVEIFS=$IFS | |
IFS=$(echo -en "\n\b") | |
for FILE in ${FILES[@]} | |
do | |
C="ffmpeg -i \""$FILE"\" $EXTRA \""$FILE".$OUTPUT_EXTENSION"\" | |
eval $C | |
done | |
IFS=$SAVEIFS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ffmpeg: ac3 5.1 -> stereo | |
ffmpeg -i input.avi -ac 2 -af "pan=stereo|FL=FC+0.30*FL+0.30*BL|FR=FC+0.30*FR+0.30*BR" output.mp4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ffmpeg: create video from image and audio | |
ffmpeg -i audio.opus -f image2 -loop 1 -i logo.png -s 640x360 -r 30 -shortest output.mp4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# amd gpu bategaz ffmpeg erabiltzeko: | |
ffmpeg -vaapi_device /dev/dri/renderD128 -i input.mp4 -vf 'format=nv12,hwupload' -c:v hevc_vaapi output.mp4 | |
ffmpeg -vaapi_device /dev/dri/renderD128 -i input.mp4 -vf 'format=nv12,hwupload' -c:v h264_vaapi output.mp4 | |
# lehenengue ariñau duest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment