ffmpeg is FLOSS (no cost), plus is the best tool to transcode/trim/demux/mux. ffmpeg is on Windows&Linux&Android OS&iOS&OSX.
[This post allows all uses.] Is now on SubStack.
Tools compatible with this howto:
- For Android OS: FFmpeg Media Encoder - Apps on Google (SilentLexx) with much success; has a visual interface to
ffmpegbut can process commands through console.- [Alternative (have not used): FFmpeg - Apps on Google (FFmpeg from CrossPlat).]
- For misc Linux OSs (suchas Ubuntu or Android OS +Termux):
apt install ffmpeg. - For iOS: https://shaunhevey.com/posts/how-to-use-ffmpeg-on-ios/.
- For OSX:
brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-libass --with-libvorbis --with-libvpx --with-opus(or alternatives). - For Windows: FFmpeg - Official app in the Microsoft Store.
You can use ../sh/Transcode.sh to do all of this for you; what follows is the manual route.
[Notice: versus stock Android, have moved default paths /Music/ to /Sounds/, /Movies/ to /Visuals/.]
[Notice: if /storage/emulated/0/ (directory root) is not found, replace with /sdcard/.]
[Notice: Can use examples with FFmpeg Media Encoder or Termux as-is (use absolute paths).]
Example visuals.mp4 was 4gb, to compress to 224mb used:
nice ffmpeg -i "/storage/emulated/0/Visuals/screen-20240629-045526.mp4" -framerate 30 -c:v libx264 -crf 32 -preset slower "/storage/emulated/0/Visuals/visuals.mp4". The libx264 codec compresses visuals best. -preset slower instructs it to compress more. You can replace -crf 32 with -b:v 2m to set an exact goal of “compress to 2mbps”.
[Notice: On some devices, Android OS’s permissions require to output to /storage/emulated/0/Download/]
Suppose you want to mux sounds.mp4 with visuals.mp4,
but you want to skip sounds.mp4’s 4 second intro, plus limit output to 2 minutes:
To demux sounds, pass -ss 4 to skip 4 seconds, pass -t 2:00 to output 2 minutes, pass -map 0:a:0 (zero-indexed) to demux first input as sounds, pass -c copy for instant process, output as .m4a:
nice ffmpeg -i "/storage/emulated/0/Download/sounds.mp4 -ss 4 -t 2:00 -map 0:a:0 -c copy "/storage/emulated/0/Sounds/demux.m4a"Now demux.m4a is 2 minutes, but visuals.m4a is much longer; pass -stream_loop -1 to mux sounds as loop to match visuals.mp4:
nice ffmpeg -i "/storage/emulated/0/Visuals/visuals.mp4" -stream_loop -1 -i "/storage/emulated/0/Sounds/demux.m4a" -map 0:v:0 -c copy -map 1:a:0 -shortest "/storage/emulated/0/Visuals/mux.mp4"Suppose you want the mix the sounds from visuals.mp4 with the loop from mux.mp4:
nice ffmpeg -i "/storage/emulated/0/Visuals/visuals.mp4" -stream_loop -1 -i "/storage/emulated/0/Sounds/demux.m4a" -map 0:a:0 -map 1:a:0 -filter_complex amix=inputs=2:duration=shortest "/storage/emulated/0/Sounds/demux2.m4a"
nice ffmpeg -i "/storage/emulated/0/Visuals/visuals.mp4" -i "/storage/emulated/0/Sounds/demux2.m4a" -map 0:v:0 -c copy -map 1:a:0 -shortest "/storage/emulated/0/Visuals/mux2.mp4"[Notice: -c copy is not compatible with -filter_complex; unless you want to reincode the visuals (slow), is 2 steps to do this]
Suppose you wish to produce a 10fps HD .gif from the first 24 seconds of visual.mp4:
nice ffmpeg -i "/storage/emulated/0/Visuals/visual.mp4" -map 0:v:0 -r 10 -s 1920x1080 -t 24 "/storage/emulated/0/Visuals/visual.gif"or, if you have ImageMagick installed (apt install magick):
nice ffmpeg -i "/storage/emulated/0/Visuals/visual.mp4" -map 0:v:0 -r 10 -s 1920x1080 -t 24 -f image2pipe -vcodec ppm - | convert -delay $(expr 100 / 10) - "/storage/emulated/0/Visuals/visual.gif"will use more disk but has dither and palette improved. Optimization (lossless compression, such as: duplicate frames and duplicate palettes are reduced).
gifsicle -O2 "/storage/emulated/0/Visuals/visual.gif" --batchLists of commands&options which ffmpeg can use:
How to use extra tools (which ffmpeg's GPLv2 version has):
https://github.com/FFmpeg/FFmpeg/blob/master/LICENSE.md
mux.mp4/mux2.mp4 syntax was used to produce:
visual.gif syntax was used to produce:
- https://www.deviantart.com/swudususuwu/art/BUD-Robos-hold-you-loop-v0-4-3-2-S-Simulator-1004148092
- https://www.deviantart.com/swudususuwu/art/Sakura-School-Simulator-howto-use-robot-props-loop-1019774750
Video Transcoder - Apps on Google (a visual interface to ffmpeg) was cool versus most “video editor” apps -- but is not available for new versions of Android OS, can not loop (just has trim + convert (which can act as demux) + resize + compress), is slow (can not pass -c copy to ffmpeg, thus always reincodes inputs.)