I am planning to use ffmpeg to ensure all video files uploaded to my website are encoded as mp4 h264.
Rather than automatically processing every file I would like to minimise the processing overhead by only processing those files that are not already mp4 h264. Is there an easy way to do this either with ffmpeg or with another command line utility?
According to FFmpeg's About page, "FFmpeg is the leading multimedia framework, able to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created." FFmpeg runs on Windows, Mac OS X, Linux, and a wide variety of other build environments and is incredibly ...
ffmpeg is a command-line tool that converts audio or video formats. It can also capture and encode in real-time from various hardware and software sources such as a TV capture card. ffplay is a simple media player utilizing SDL and the FFmpeg libraries.
FFmpeg is a great tool for quickly changing an AV file's format or quality, extracting audio, creating GIFs, and more. There are many open source tools out there for editing, tweaking, and converting multimedia into exactly what you need.
ffprobe
$ ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=nokey=1:noprint_wrappers=1 input.mp4
h264
-v error
Omit extra information except for fatal errors.
-select_streams v:0
Select only the first video stream. Otherwise the codec_name
for all other streams in the file, such as audio, will be shown as well.
-show_entries stream=codec_name
Only output the codec_name
instead of all stream info.
-of default=nokey=1:noprint_wrappers=1
Select the default output format style and omit the key and wrapper info. Otherwise, without these options, it will output:
[STREAM] codec_name=h264 [/STREAM]
ffprobe
documentationOnly re-encode if video is not H.264:
#!/bin/bash mkdir h264vids for f in *.mkv do audioformat=$(ffprobe -loglevel error -select_streams v:0 -show_entries stream=codec_name -of default=nw=1:nk=1 "$f") if [ "$audioformat" = "h264" ]; then ffmpeg -i "$f" -c:v copy -c:a aac -movflags +faststart h264vids/"${f%.*}.mp4" else ffmpeg -i "$f" -c:v libx264 -c:a aac -movflags +faststart h264vids/"${f%.*}.mp4" fi done
This is a simple script and will ignore additional video streams if you input has more than one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With