silicontrip / lavtools

mjpeg utils and avcodec frame based video editing tools and ffmpeg filters
15 stars 3 forks source link

gnuplot example #5

Closed Nikoli closed 11 years ago

Nikoli commented 11 years ago

Please add example of script or/and commands for generating graphs from libav-bitrate output.

Nikoli commented 11 years ago

Made simple script:

#!/bin/bash
# plot-bitrate.sh

check_file_e() {
    if [ ! -s "${1}" ]
    then
        echo "ERROR: \"${1}\" does not exist or is empty"
        exit 1
    fi
}

media_file="${1}"
check_file_e "${media_file}"
media_name="$(basename "${media_file}")"
data_file="$(mktemp ~/.plot-bitrate.sh_"${media_name}"_data.XXXXX)"
info_file="$(mktemp ~/.plot-bitrate.sh_"${media_name}"_info.XXXXX)"
streams_file="$(mktemp ~/.plot-bitrate.sh_"${media_name}"_streams.XXXXX)"

/usr/local/bin/libav-bitrate "${media_file}" 2> "${info_file}" > "${data_file}"

grep -e '^[ ]*Stream #' "${info_file}"|sed -e 's,^[ ]*,,' >  "${streams_file}"

for i in "${info_file}" "${data_file}" "${streams_file}"
do
    check_file_e "${i}"
done

{
echo "
set title \"${media_name}\"
set xdata time
set timefmt '%s'
set format x '%R'
set xlabel 'time'
set ylabel 'bitrate (Kb/s)'
set style data lines

set terminal qt size 1910,960
"
echo -n 'plot "'"${data_file}"'" using 1:($2/1024) title "all"'
stream_n='2'
cat "${streams_file}"|while read line
do
    stream_n="$[${stream_n}+1]"
    echo -n ', "'"${data_file}"'" using 1:($'"${stream_n}"'/1024) title "'"${line}"'"'
done
echo
}|gnuplot --persist
rm -v "${info_file}" "${data_file}" "${streams_file}"

Do you have any suggestions?

I am not sure if graphs are correct. Constant bitrate: http://i.imgur.com/DQrAI.png Sample from DVDrip: http://i.imgur.com/B1xO2.png

silicontrip commented 11 years ago

Those graphs look pretty much correct. I don't have much of a way to verify that what the graph is showing is correct. It's been a while since I've used gnu-plot. (I've been using this http://plot.micw.eu/) I only used it for visual reference. I didn't do much with titles or legends. If there is any meta data you need output in a specific form that would help the plot let me know.

Nikoli commented 11 years ago

I think there are no problems with parsing avprobe format. Fixing issue #6 and issue #7 will help much.

silicontrip commented 11 years ago

I assume that this all working.

Nikoli commented 11 years ago

Will you add this script or some other to git? If yes, i will provide updated version.