Last active
September 18, 2020 18:54
-
-
Save kolibril13/19ed021ad56c464d36643063991ea5aa to your computer and use it in GitHub Desktop.
Video Cutting with ffmpeg
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
# Output every single frame from the video into an image file: | |
ffmpeg -i "input.mp4" frames/out_%03d.png | |
ffmpeg -i input.mp4 output.webm | |
# Trim off fist 2 seconds: | |
ffmpeg -i input.mkv -ss 2 -vcodec copy -acodec copy output.flv | |
# Extract fist 10 seconds: | |
ffmpeg -i input.mkv -ss 0 -t 10 out.mkv | |
# Extract last 10 seconds | |
ffmpeg -sseof -10 -i input.mp4 output.mp4 | |
# Convert to gif: | |
ffmpeg -i input.mp4 -r 12 -s 320x180 output.gif | |
#counting frames: | |
ffmpeg -i input.mp4 -map 0:v:0 -c copy -f null -y /dev/null 2>&1 | grep -Eo 'frame= *[0-9]+ *' | grep -Eo '[0-9]+' | tail -1 | |
#OR: | |
ffprobe -v error -select_streams v:0 -show_entries stream=nb_frames -of default=nokey=1:noprint_wrappers=1 input.mp4 | |
#extract frame number 20: | |
ffmpeg -i input.mp4 -vf "select=gte(n\,20)" -vframes 1 out_img.png | |
#compress an mp4 file more or less lossless: | |
ffmpeg -i input.mp4 -vcodec h264 -acodec aac output.mp4 | |
with python script: | |
```python | |
from pathlib import Path | |
import os | |
suffix = ".mp4" | |
input_path= Path.home() / "Desktop/foo" | |
file_paths= [subp for subp in input_path.rglob('*') if suffix == subp.suffix] | |
file_paths.sort() | |
output_path = Path.home() / "Desktop/foo/final" | |
output_path.mkdir(parents=True, exist_ok=True) | |
for file_p in file_paths: | |
input = str(file_p) | |
output = str( output_path / file_p.name ) | |
command = f"ffmpeg -i {input} -vcodec libx265 -crf 28 -acodec aac {output}" | |
print(command) | |
os.system(command) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment