Reputation: 1424
I have some Mp4 files. I want to get the bitrate of the video track and audio track separately with python. I know that python-opencv
may help to get the number of frames:
import cv2
video = "sample.mp4"
video_capture = cv2.VideoCapture(video)
video_length = int(video_capture.get(cv2.CAP_PROP_FRAME_COUNT))
But I didn't find an option for biterate. And I don't need the bitrate overall because I have to process the video and audio separately. (If the audio biterate can be computed by the others, that's alright.) I don't know if python-opencv
can make it. If not, what other packages should I use and how?
Use popular packages as much as possible to avoid problems. It's better if stream setting is checked. Thank you.
Upvotes: 3
Views: 3472
Reputation: 25471
ffmpeg is probably the most common or popular solution for video manipulation and you cam use it to get the information you are looking for.
Although ffmpeg is a command line tool, the libraries it is built on can be used in other app and for your case, probably more simply, Python wrappers exist that allow you use all the functionality of command line ffmpeg. For example the following is a well supported one (at the time of writing):
This library includes examples to get info using ffprobe (companion command line utility to ffmpeg) - the return is JSON and you can search for the info you need in wither the video or audio stream - e.g.:
probe = ffmpeg.probe(args.in_filename)
video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
Upvotes: 3