I am trying to create a script to process videos, but I was hoping to get bit_rate, width, and height info from the incoming files so I could better tune the output. The script works when I do the files one at a time, but when I put it into a loop all of a sudden I don't get any info.
So this works:
#!/bin/bash
eval $(ffprobe -v quiet -show_format -of flat=s=_ -show_entries stream=height,width,nb_frames,duration,codec_name input.mp4);
width=${streams_stream_0_width};
height=${streams_stream_0_height};
bitrate=$((${format_bit_rate}/1000));
echo $width,$height,$bitrate;
This doesn't when executed from find ./ -type f -regex ".*\.\(mkv\|mp4\|wmv\|flv\|webm\|mov\|avi\)" -print0 | xargs -0 /root/newbatch.sh
for i; do
eval '$(ffprobe -v quiet -show_format -of flat=s=_ -show_entries stream=height,width,nb_frames,duration,codec_name $i)';
width=${streams_stream_0_width};
height=${streams_stream_0_height};
bitrate=${format_bit_rate};
kbitrate=$((bitrate/1000));
echo $i,$width,$height,$kbitrate;
done
I also get an error with the math of bitrate
in the loop, but even when I comment it out I still get no results. Since it works one at a time, I am assuming the problem is a bash scripting and nothing to do with ffmpeg / ffprobe.
That being said, I can do this:
echo $i,$width,$height,$bitrate;
and get back
./file1.mkv,,,
./file2.mkv,,,
./file3.mkv,,,
./file4.mkv,,,
So it does get some info back, but it loses the info from the eval statement.
I found the problem was files with whitespaces in the
$i
variable.This code combines all the commands into a single shell command that searches the current folder and all subdirectories for all video files, loops though with some options to setup bitrate settings for different resolutions along with some other things to spruce it up.