I'm using ffmpeg-python to fetch streams from a video and write some parameters (codec_name, resolution, etc.) for each stream into csv.
video = 'test.mkv'
probe = ffmpeg.probe(video)
video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
print(video_stream['codec_long_name'])
audio_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'audio'), None)
...
My problem is that it works well for a video stream, but not for multiple audio (or subtitles) streams. If the video has several audio streams it returns only one audio stream.
I've tried another approach, but it returns some streams 2-3 times and I get duplicates. So if the video sample has 4 audio tracks, I end up with ~9 audio streams instread of 4.
audio_streams = []
for audio in (probe['streams']):
if (audio['codec_type'] == 'audio'):
audio_streams.append(audio)
pprint(audio_streams)
All other ideas I tried don't work, I'm new to programming and I'm stuck with it. How can I get all audio streams from a file without duplicates?