Last active
February 18, 2022 08:04
-
-
Save garcon/c4039efa8b343d8a8372bd90611624d3 to your computer and use it in GitHub Desktop.
This is a collection of command line one-liners for manipulating with audio and video files
This file contains hidden or 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
## Write list of videos in a text file | |
$ cat mylist.txt | |
file '/path/to/file1' | |
file '/path/to/file2' | |
file '/path/to/file3' | |
## Concatenate videos | |
$ ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp4 | |
# -f concat => filter concatenate | |
# -safe 0 => safe mode for paths | |
# -i => input | |
# -c copy => use the same codec as origin |
This file contains hidden or 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
## Convert video to H.265/HVEC | |
ffmpeg -i input.mp4 -c:v libx265 -tag:v hvc1 output.mp4 | |
# -c:v libx265 => for video use codec H.265 (HEVC) | |
# -c:v hevc_videotoolbox => for video use codec H.265 (HEVC) with hardware acceleration on Apple (faster, but lower quality) | |
# -tag:v hvc1 => enable playing in Apple QuickTime |
This file contains hidden or 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
## Crop video | |
ffmpeg -i input.mp4 -vf "crop=output_w:output_h:x:y" output.mp4 | |
# output_w => output width | |
# output_h => output height | |
# x:y => left top corner | |
# -vf "crop=input_w/2:input_h/2:input_w/2:input_h/2" | |
# input_w => input width | |
# input_h => input height | |
# -vf "crop=320/2:240/2:320/2:240/2" | |
# -vf "crop=in_w:in_h-40" | |
## Detect cropping boundaries | |
ffplay -i input.mp4 -vf cropdetect |
This file contains hidden or 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
## Combine video with audio, audio is delayed (shifted, in offset) 75 seconds | |
ffmpeg -i video.mp4 -itsoffset 75 -i audio.m4a -c:v copy -c:a copy -map 0:v -map 1:a output.mp4 | |
# -itsoffset 75 => following file input is 75 seconds delayed | |
# -c:v copy => copy video codec | |
# -c:a copy => copy audio codec | |
# -map 0:v => from the first input take a video stream | |
# -map 1:a => from the second input take a audio stream | |
# -i => input file |
This file contains hidden or 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
## Inspect original audio format | |
ffprobe video.mp4 | |
## Extract audio | |
ffmpeg -i video.mp4 -vn -c:a copy audio.m4a | |
# -vn => -vn / -an / -sn / -dn options can be used to skip inclusion | |
# of video, audio, subtitle and data streams respectively | |
# -c:a copy 5 => audio codec copy |
This file contains hidden or 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
## Convert image to video 1. | |
convert -quality 100 -delay 5 image.png video.mp4 | |
# -quality 100 => quality of compression (0 worst quality -- 100 best quality) | |
# -delay 5 => 5 seconds length of video | |
## Convert image to video 2. | |
ffmpeg -loop 1 -i screen-00.png -c:v libx265 -t 10 -pix_fmt yuv420p screen-00.mp4 | |
# -loop 1 => ??? | |
# -t 10 => length od 10 s | |
# -pix_fmt yuv420p => pixel format. |
This file contains hidden or 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
## Print info about video | |
ffprobe input.mp4 |
This file contains hidden or 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
## Preview video | |
ffplay -i input.mp4 -vf "crop=in_w:in_h-40" |
This file contains hidden or 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
## Resize video | |
ffmpeg -i input.mp4 -vf scale="720:480" output.mp4 | |
# -vf scale="720:-1" => width 720 px and keep ratio | |
# -vf scale="720:-2" => width 720 px, keep ratio and round height to even number (important for h.264) | |
# -vf scale="iw/1:ih/2" => keep the same width and divide height by 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment