+void set_pixel_format(AVFilterContext* sink, AVPixelFormat pix_fmt)
+{
+#pragma warning (push)
+#pragma warning (disable : 4245)
+
+ FF(av_opt_set_int_list(
+ sink,
+ "pix_fmts",
+ std::vector<AVPixelFormat>({ pix_fmt, AVPixelFormat::AV_PIX_FMT_NONE }).data(),
+ -1,
+ AV_OPT_SEARCH_CHILDREN));
+
+#pragma warning (pop)
+}
+
+void adjust_video_filter(const AVCodec& codec, const core::video_format_desc& in_format, AVFilterContext* sink, std::string& filter)
+{
+ switch (codec.id)
+ {
+ case AV_CODEC_ID_DVVIDEO:
+ // Crop
+ if (in_format.format == core::video_format::ntsc)
+ filter = u8(append_filter(u16(filter), L"crop=720:480:0:2"));
+
+ // Pixel format selection
+ if (in_format.format == core::video_format::ntsc)
+ set_pixel_format(sink, AVPixelFormat::AV_PIX_FMT_YUV411P);
+ else if (in_format.format == core::video_format::pal)
+ set_pixel_format(sink, AVPixelFormat::AV_PIX_FMT_YUV420P);
+ else
+ set_pixel_format(sink, AVPixelFormat::AV_PIX_FMT_YUV422P);
+
+ // Scale
+ if (in_format.height == 1080)
+ filter = u8(append_filter(u16(filter), in_format.duration == 1001
+ ? L"scale=1280:1080"
+ : L"scale=1440:1080"));
+ else if (in_format.height == 720)
+ filter = u8(append_filter(u16(filter), L"scale=960:720"));
+
+ break;
+ }
+}
+
+void setup_codec_defaults(AVCodecContext& encoder)
+{
+ static const int MEGABIT = 1000000;
+
+ switch (encoder.codec_id)
+ {
+ case AV_CODEC_ID_DNXHD:
+ encoder.bit_rate = 220 * MEGABIT;
+
+ break;
+ case AV_CODEC_ID_PRORES:
+ encoder.bit_rate = encoder.width < 1280
+ ? 63 * MEGABIT
+ : 220 * MEGABIT;
+
+ break;
+ case AV_CODEC_ID_H264:
+ av_opt_set(encoder.priv_data, "preset", "ultrafast", 0);
+ av_opt_set(encoder.priv_data, "tune", "fastdecode", 0);
+ av_opt_set(encoder.priv_data, "crf", "5", 0);
+
+ break;
+ }
+}
+