I have several videos in a folder;
~/Downloads/movie1.mkv
~/Downloads/movie2.mkv
~/Downloads/movie3.mkv
I would like to extract the bitrate for each file, and output the data into a single text file, or output list which I can copy and paste into a text file.
I have installed ffmpeg.
So, for example, the output of ffmpeg -i movie1.mkv
is;
Metadata:
encoder : libebml v1.2.0 + libmatroska v1.1.0
creation_time : 2011-04-09T18:18:05.000000Z
Duration: 00:04:27.71, start: 0.000000, bitrate: 10698 kb/s
Stream #0:0(eng): Video: h264 (High), yuv420p(progressive), 1920x1038, SAR 1:1 DAR 320:173, 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Metadata:
title : movie1
Stream #0:1(eng): Audio: dts (DTS), 48000 Hz, 5.1(side), fltp, 1536 kb/s (default)
Metadata:
title : DTS-ES 5.1 @ 1509 Kbps
Stream #0:2(eng): Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
Metadata:
title : Commentary
Stream #0:3(eng): Subtitle: subrip
Stream #0:4(eng): Subtitle: subrip
The "bitrate: 10698 kb/s" is the crucial part I am after here.
Let's pretend all three movies have the same bitrate.
I would like to extract the bitrate information from all three videos, and have them output as;
movie1.mkv 10698
movie2.mkv 10698
movie3.mkv 10698
How would I go about extracting and outputing this information in bulk?
I've been trying a combination of finding by file name, ffmpeg, and then | to grep. e.g ; find . -name "*.mkv" -exec ffmpeg -i "${1%.mkv}" | grep "bitrate:"
Current attempts;
The command
ffmpeg -i movie1.mkv 2>&1 | grep bitrate | sed 's/bitrate: \(.*\), kb/\1/g'
returns
Duration: 00:04:27.71, start: 0.000000, bitrate: 10698 kb/s
The command
find . -name "*.mkv" -exec ffprobe -v error -show_entries format=bit_rate -of default=noprint_wrappers=1:nokey=1 "${~/Downloads/1%.mkv}" ';`'
returns
~/Downloads/1%.mkv: No such file or directory ~/Downloads/1%.mkv: No such file or directory ~/Downloads/1%.mkv: No such file or directory
I feel that I'm close here, and that there's just something wrong with the find and recalling the output of find into ffprobe.
To screen:
To file result.txt:
You will see in file result.txt:
Formatted output example:
You will see in file result.txt: