summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2022-06-20 14:13:43 +0200
committerAnton Khirnov <anton@khirnov.net>2022-07-28 16:37:16 +0200
commit1a464efae3e3fda60630ea38fbc5d84dcf614340 (patch)
tree7e5a899db0438d780563196cd8d81e0711e9ee00
parentecfdab20e4acd7697f7f37f73b42de3622305aa4 (diff)
fftools/ffmpeg_opt: factor auto-mapping video out of open_output_file()
-rw-r--r--fftools/ffmpeg_opt.c84
1 files changed, 46 insertions, 38 deletions
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index e6f2fb597a..4d2cd13107 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -2495,6 +2495,50 @@ static int setup_sync_queues(OutputFile *of, AVFormatContext *oc, int64_t buf_si
return 0;
}
+static void map_auto_video(OutputFile *of, AVFormatContext *oc,
+ OptionsContext *o)
+{
+ InputStream *ist;
+
+ /* video: highest resolution */
+ if (av_guess_codec(oc->oformat, NULL, oc->url, NULL, AVMEDIA_TYPE_VIDEO) != AV_CODEC_ID_NONE) {
+ int best_score = 0, idx = -1;
+ int qcr = avformat_query_codec(oc->oformat, oc->oformat->video_codec, 0);
+ for (int j = 0; j < nb_input_files; j++) {
+ InputFile *ifile = input_files[j];
+ int file_best_score = 0, file_best_idx = -1;
+ for (int i = 0; i < ifile->nb_streams; i++) {
+ int score;
+ ist = input_streams[ifile->ist_index + i];
+ score = ist->st->codecpar->width * ist->st->codecpar->height
+ + 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS)
+ + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
+ if (ist->user_set_discard == AVDISCARD_ALL)
+ continue;
+ if((qcr!=MKTAG('A', 'P', 'I', 'C')) && (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
+ score = 1;
+ if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
+ score > file_best_score) {
+ if((qcr==MKTAG('A', 'P', 'I', 'C')) && !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
+ continue;
+ file_best_score = score;
+ file_best_idx = ifile->ist_index + i;
+ }
+ }
+ if (file_best_idx >= 0) {
+ if((qcr == MKTAG('A', 'P', 'I', 'C')) || !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
+ file_best_score -= 5000000*!!(input_streams[file_best_idx]->st->disposition & AV_DISPOSITION_DEFAULT);
+ if (file_best_score > best_score) {
+ best_score = file_best_score;
+ idx = file_best_idx;
+ }
+ }
+ }
+ if (idx >= 0)
+ new_video_stream(o, oc, idx);
+ }
+}
+
static int open_output_file(OptionsContext *o, const char *filename)
{
AVFormatContext *oc;
@@ -2573,44 +2617,8 @@ static int open_output_file(OptionsContext *o, const char *filename)
if (!o->nb_stream_maps) {
char *subtitle_codec_name = NULL;
/* pick the "best" stream of each type */
-
- /* video: highest resolution */
- if (!o->video_disable && av_guess_codec(oc->oformat, NULL, filename, NULL, AVMEDIA_TYPE_VIDEO) != AV_CODEC_ID_NONE) {
- int best_score = 0, idx = -1;
- int qcr = avformat_query_codec(oc->oformat, oc->oformat->video_codec, 0);
- for (j = 0; j < nb_input_files; j++) {
- InputFile *ifile = input_files[j];
- int file_best_score = 0, file_best_idx = -1;
- for (i = 0; i < ifile->nb_streams; i++) {
- int score;
- ist = input_streams[ifile->ist_index + i];
- score = ist->st->codecpar->width * ist->st->codecpar->height
- + 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS)
- + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
- if (ist->user_set_discard == AVDISCARD_ALL)
- continue;
- if((qcr!=MKTAG('A', 'P', 'I', 'C')) && (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
- score = 1;
- if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
- score > file_best_score) {
- if((qcr==MKTAG('A', 'P', 'I', 'C')) && !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
- continue;
- file_best_score = score;
- file_best_idx = ifile->ist_index + i;
- }
- }
- if (file_best_idx >= 0) {
- if((qcr == MKTAG('A', 'P', 'I', 'C')) || !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
- file_best_score -= 5000000*!!(input_streams[file_best_idx]->st->disposition & AV_DISPOSITION_DEFAULT);
- if (file_best_score > best_score) {
- best_score = file_best_score;
- idx = file_best_idx;
- }
- }
- }
- if (idx >= 0)
- new_video_stream(o, oc, idx);
- }
+ if (!o->video_disable)
+ map_auto_video(of, oc, o);
/* audio: most channels */
if (!o->audio_disable && av_guess_codec(oc->oformat, NULL, filename, NULL, AVMEDIA_TYPE_AUDIO) != AV_CODEC_ID_NONE) {