Skip to content

Commit e4772ef

Browse files
committed
ffmpeg: Set default output format to hwaccel's native format
I think this is usually what the user wants - if they are using an hwaccel, they probably want full hardware transcoding to work.
1 parent 34d2841 commit e4772ef

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

ffmpeg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ typedef struct HWAccel {
7777
enum HWAccelID id;
7878
enum AVPixelFormat pix_fmt;
7979
enum AVHWDeviceType device_type;
80+
int pix_fmt_is_default;
8081
} HWAccel;
8182

8283
typedef struct HWDevice {

ffmpeg_opt.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,31 +68,31 @@
6868
const HWAccel hwaccels[] = {
6969
#if HAVE_VDPAU_X11
7070
{ "vdpau", hwaccel_decode_init, HWACCEL_VDPAU, AV_PIX_FMT_VDPAU,
71-
AV_HWDEVICE_TYPE_VDPAU },
71+
AV_HWDEVICE_TYPE_VDPAU, FALSE },
7272
#endif
7373
#if HAVE_DXVA2_LIB
7474
{ "dxva2", dxva2_init, HWACCEL_DXVA2, AV_PIX_FMT_DXVA2_VLD,
75-
AV_HWDEVICE_TYPE_NONE },
75+
AV_HWDEVICE_TYPE_NONE, FALSE },
7676
#endif
7777
#if CONFIG_VDA
7878
{ "vda", videotoolbox_init, HWACCEL_VDA, AV_PIX_FMT_VDA,
79-
AV_HWDEVICE_TYPE_NONE },
79+
AV_HWDEVICE_TYPE_NONE, FALSE },
8080
#endif
8181
#if CONFIG_VIDEOTOOLBOX
8282
{ "videotoolbox", videotoolbox_init, HWACCEL_VIDEOTOOLBOX, AV_PIX_FMT_VIDEOTOOLBOX,
83-
AV_HWDEVICE_TYPE_NONE },
83+
AV_HWDEVICE_TYPE_NONE, FALSE },
8484
#endif
8585
#if CONFIG_LIBMFX
8686
{ "qsv", qsv_init, HWACCEL_QSV, AV_PIX_FMT_QSV,
87-
AV_HWDEVICE_TYPE_NONE },
87+
AV_HWDEVICE_TYPE_NONE, TRUE },
8888
#endif
8989
#if CONFIG_VAAPI
9090
{ "vaapi", hwaccel_decode_init, HWACCEL_VAAPI, AV_PIX_FMT_VAAPI,
91-
AV_HWDEVICE_TYPE_VAAPI },
91+
AV_HWDEVICE_TYPE_VAAPI, FALSE },
9292
#endif
9393
#if CONFIG_CUVID
9494
{ "cuvid", hwaccel_decode_init, HWACCEL_CUDA, AV_PIX_FMT_CUDA,
95-
AV_HWDEVICE_TYPE_CUDA },
95+
AV_HWDEVICE_TYPE_CUDA, TRUE },
9696
#endif
9797
{ 0 },
9898
};
@@ -708,6 +708,7 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
708708
char *discard_str = NULL;
709709
const AVClass *cc = avcodec_get_class();
710710
const AVOption *discard_opt = av_opt_find(&cc, "skip_frame", NULL, 0, 0);
711+
enum AVPixelFormat default_pix_fmt = AV_PIX_FMT_NONE;
711712

712713
if (!ist)
713714
exit_program(1);
@@ -805,6 +806,8 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
805806
for (i = 0; hwaccels[i].name; i++) {
806807
if (!strcmp(hwaccels[i].name, hwaccel)) {
807808
ist->hwaccel_id = hwaccels[i].id;
809+
if (hwaccels[i].pix_fmt_is_default)
810+
default_pix_fmt = hwaccels[i].pix_fmt;
808811
break;
809812
}
810813
}
@@ -837,7 +840,7 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
837840
"format: %s", hwaccel_output_format);
838841
}
839842
} else {
840-
ist->hwaccel_output_format = AV_PIX_FMT_NONE;
843+
ist->hwaccel_output_format = default_pix_fmt;
841844
}
842845

843846
ist->hwaccel_pix_fmt = AV_PIX_FMT_NONE;

0 commit comments

Comments
 (0)