Skip to content

FFMpeg Notes

Raspi Mount USB

pi ip: 30

the drive is under “/media/pi/’whatever’“

Notes on MPG4 Encoding

References:

https://ottverse.com/change-resolution-resize-scale-video-using-ffmpeg/

https://trac.ffmpeg.org/wiki/Encode/H.264

HTML5 MP4 ffmpeg encoding

variable bit rate 1080p MP3:

ffmpeg -i input_video -vcodec libx264 -crf 25 -preset medium -vf scale=-2:1080 -acodec libmp3lame -q:a 4 -ar 48000 -ac 2 output_video.mp4

fixed bit rate 1080p MP2:

ffmpeg -i input_video -vcodec libx264 -b:v 1000k -vf scale=-2:1080 -acodec mp2 -b:a 256k -ar 48000 -ac 2 output_video.mp4

no audio:

ffmpeg -i input_video -vcodec libx264 -b:v 1000k -vf scale=-2:1080 -an output_video.mp4

crop size (width:height:xoffset:yoffset):

ffmpeg -i input_video -vf crop=1500:800:200:100 -vcodec libx264 -b:v 1000k -an output_video.mp4

trim time (-ss start time, -t duration):

ffmpeg -i input_video -vcodec libx264 -b:v 1000k -an -ss 00:00:10 -t 00:00:10 output_video.mp4

mix audio and video:

ffmpeg -i input_video -vcodec libx264 -b:v 1000k -vf crop=1120:876:0:100 -i input_audio -acodec mp2 -b:a 256k -ar 48000 -ac 2 -ss 00:00:20 -t 00:00:20 output_video.mp4

crop, pan, composite:

ffmpeg -i input_video_1 -i input_video_2 -filter_complex ‘[1:v]crop=175:95:930:860[cropout];[cropout]scale=350:190[scaleout];[0:v][scaleout]overlay=10:10[outv]’ -map ‘[outv]’ -vcodec libx264 -b:v 1000k -map 0:a -acodec mp2 -b:a 256k -ac 2 -t 00:00:05 output_video.mp4

numbered images to video:

ffmpeg -r 30 -i %04d.jpg -vcodec libx264 -b:v 1000k -vf scale=-2:1080 -an output_video.mp4

And what I used and output.

For no sound

pi@raspberrypi:/media/pi/16 GB/Fab Lab/vids $ ffmpeg -i PXL_20220215_002428428_2.mp4 
-vcodec libx264 -crf 25 -preset medium -vf scale=-2:1080 -an laser_cutter.mp4

You can also scale down the video for smaller file sizes:

ffmpeg -i PXL_20220429_172244588.mp4 -vcodec libx264 -crf 26 -preset slow -vf scale=-1:720 -an i2c_blink.mp4

"-crf 25" is the lossyness/qualtiy. 0 is lossless, 25 is considered average, 50 would be horrible(?) quality.

"-preset" is time it takes.  medium is default, slow and slower should do better job of compression, but of course take more time to process. Fore more, see: <https://trac.ffmpeg.org/wiki/Encode/H.264>

"-scale" is the scale, and the "-1:720" means to keep the vertical scale, and base the horizontal on the 720p. (in this case.)  For more, see: <https://ottverse.com/change-resolution-resize-scale-video-using-ffmpeg/>

For Sound

ffmpeg -i PXL_20220324_210534689_2.mp4 -vcodec libx264 -crf 25 -preset medium -vf scale=-2:1080 -acodec libmp3lame -q:a 4 -ar 48000 -ac 2 mill_group_part_sound.mp4

Adding videos

see: https://fabacademy.org/2021/labs/kannai/instruction/tips/video_path_test/


Last update: May 6, 2022