2

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 fffmpeg -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.

Lets 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;

1. 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

2. 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.

1

To screen:

find . -name "*.mkv" -print0 | xargs -0 -i{} sh -c " echo -n '{} ' && ffmpeg -i '{}' 2>&1 | sed -n -e 's/^.*bitrate: //p' "

To file result.txt:

find . -name "*.mkv" -print0 | xargs -0 -i{} sh -c " echo -n '{} ' && ffmpeg -i '{}' 2>&1 | sed -n -e 's/^.*bitrate: //p' " > result.txt

You will see in file result.txt:

somefile1.mkv 1788 kb/s
somefile2.mkv 1681 kb/s
...

Formatted output example:

find . -name "*.mkv" -print0 | xargs -0 -i{} sh -c " echo -n 'Filename: {}, Bitrate is: ' && ffmpeg -i '{}' 2>&1 | sed -n -e 's/^.*bitrate: //p' " > result.txt

You will see in file result.txt:

Filename: somefile1.mkv, Bitrate is: 1788 kb/s
Filename: somefile2.mkv, Bitrate is: 1681 kb/s
...
  • I keep getting the "missing argument to `-exec " error – Martin JS Nov 13 '18 at 11:56
  • Try: find . -name "*.mkv" -exec ffmpeg -i "${1%.mkv}" | sed -n -e 's/^.*bitrate: //p' What output you get? – mature Nov 13 '18 at 12:01
  • Still getting the "missing argument to `-exec " error. I have found that : ffprobe -v error -show_entries format=bit_rate -of default=noprint_wrappers=1:nokey=1 "movie1.mkv" returns just the bit rate, so if somehow the output of find, and the use echo can be used with that, it might do the trick – Martin JS Nov 13 '18 at 12:03
  • I added the ';', and it returned with a "No such file or directory error three times, so I think there's an issue in the finding of the file name, and passing it to ffmpeg. – Martin JS Nov 13 '18 at 12:39
  • I found errors and edited my answer with some new examples – mature Nov 13 '18 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.