I have a video downloaded from Telegram and I need to determine its bitrate.
I have moviepy (pip install moviepy, not the developer version).
Also, I have ffmpeg, but I don’t know how to use it in python.
Also, any other library would work for me.
Question posted in Telegram API
A comprehensive official documentation can be found here.
A comprehensive official documentation can be found here.
3
Answers
Here is a solution using FFprobe:
ffprobe
(command line tool) as sub-process and read the content ofstdout
.Use the argument
-print_format json
for getting the output in JSON format.For getting only the
bit_rate
entry, add argument-show_entries stream=bit_rate
.dict = json.loads(data)
.int
:bit_rate = int(dict['streams'][0]['bit_rate'])
.The code sample creates a sample video file for testing (using FFmpeg), and get the bitrate (using FFprobe):
Notes:
bit_rate
information so different solution is needed.Solution for containers that has no
bit_rate
information (like MKV):Based on the following post, we can sum the size of all the video packets.
We can also sum all the packets durations.
The average bitrate equals:
total_size_in_bits / total_duration_in_seconds
.Here is a code sample for computing average bitrate for MKV video file:
http://timivanov.ru/kak-uznat-bitrate-i-fps-video-ispolzuya-python-i-ffmpeg/
try this:
except Exception as er:
return er