PyAV-Org / PyAV

Pythonic bindings for FFmpeg's libraries.
https://pyav.basswood-io.com/
BSD 3-Clause "New" or "Revised" License
2.44k stars 359 forks source link

Support `av_find_best_stream` #1481

Closed rectalogic closed 1 month ago

rectalogic commented 1 month ago

Overview

Add support for av_find_best_stream to StreamContainer

Desired Behavior

Using the C libav APIs I would usually first find the "best" video stream, and then find the "best" related audio stream:

int video_stream_index = av_find_best_stream(format_context, AVMEDIA_TYPE_VIDEO, -1, -1, &video_codec, 0);
int audio_stream_index = av_find_best_stream(format_context, AVMEDIA_TYPE_AUDIO, -1, video_stream_index, &audio_codec, 0);

Example API

StreamContainer.get is pretty overloaded, maybe a new API like StreamContainer.best(type: str, related: Stream | None) -> Stream where type is Stream.type ?

moonsikpark commented 1 month ago

makes sense to me