ffmpeg: move field order decision making to encoder initialization

We now have the possibility of getting AVFrames here, and we should
not touch the muxer's codecpar after writing the header.

Results of FATE tests change as the MXF and Matroska muxers actually
write down the field/frame coding type of a stream in their
respective headers. Before this change, these values in codecpar
would only be set after the muxer was initialized. Now, the
information is also available for encoder and muxer initialization.
This commit is contained in:
Jan Ekström 2020-09-20 21:00:52 +03:00
parent 7369595c55
commit fbb44bc51a
5 changed files with 19 additions and 18 deletions

View File

@ -1123,7 +1123,6 @@ static void do_video_out(OutputFile *of,
int ret, format_video_sync; int ret, format_video_sync;
AVPacket pkt; AVPacket pkt;
AVCodecContext *enc = ost->enc_ctx; AVCodecContext *enc = ost->enc_ctx;
AVCodecParameters *mux_par = ost->st->codecpar;
AVRational frame_rate; AVRational frame_rate;
int nb_frames, nb0_frames, i; int nb_frames, nb0_frames, i;
double delta, delta0; double delta, delta0;
@ -1285,18 +1284,6 @@ static void do_video_out(OutputFile *of,
if (!check_recording_time(ost)) if (!check_recording_time(ost))
return; return;
if (enc->flags & (AV_CODEC_FLAG_INTERLACED_DCT | AV_CODEC_FLAG_INTERLACED_ME) &&
ost->top_field_first >= 0)
in_picture->top_field_first = !!ost->top_field_first;
if (in_picture->interlaced_frame) {
if (enc->codec->id == AV_CODEC_ID_MJPEG)
mux_par->field_order = in_picture->top_field_first ? AV_FIELD_TT:AV_FIELD_BB;
else
mux_par->field_order = in_picture->top_field_first ? AV_FIELD_TB:AV_FIELD_BT;
} else
mux_par->field_order = AV_FIELD_PROGRESSIVE;
in_picture->quality = enc->global_quality; in_picture->quality = enc->global_quality;
in_picture->pict_type = 0; in_picture->pict_type = 0;
@ -3433,6 +3420,20 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame)
enc_ctx->field_order = AV_FIELD_TT; enc_ctx->field_order = AV_FIELD_TT;
} }
if (frame) {
if (enc_ctx->flags & (AV_CODEC_FLAG_INTERLACED_DCT | AV_CODEC_FLAG_INTERLACED_ME) &&
ost->top_field_first >= 0)
frame->top_field_first = !!ost->top_field_first;
if (frame->interlaced_frame) {
if (enc_ctx->codec->id == AV_CODEC_ID_MJPEG)
enc_ctx->field_order = frame->top_field_first ? AV_FIELD_TT:AV_FIELD_BB;
else
enc_ctx->field_order = frame->top_field_first ? AV_FIELD_TB:AV_FIELD_BT;
} else
enc_ctx->field_order = AV_FIELD_PROGRESSIVE;
}
if (ost->forced_keyframes) { if (ost->forced_keyframes) {
if (!strncmp(ost->forced_keyframes, "expr:", 5)) { if (!strncmp(ost->forced_keyframes, "expr:", 5)) {
ret = av_expr_parse(&ost->forced_keyframes_pexpr, ost->forced_keyframes+5, ret = av_expr_parse(&ost->forced_keyframes_pexpr, ost->forced_keyframes+5,

View File

@ -1 +1 @@
d66177ea3922692bc91cd0f8aa907650 *tests/data/fate/concat-demuxer-extended-lavf-mxf_d10.ffprobe 84496cfe2d668db395280ea67e5c6fbe *tests/data/fate/concat-demuxer-extended-lavf-mxf_d10.ffprobe

View File

@ -78,5 +78,5 @@ video|0|34|1.360000|34|1.360000|1|0.040000|N/A|N/A|150000|1924096|K_|1
Strings Metadata Strings Metadata
audio|1|65280|1.360000|65280|1.360000|1920|0.040000|N/A|N/A|7680|2074624|K_|1 audio|1|65280|1.360000|65280|1.360000|1920|0.040000|N/A|N/A|7680|2074624|K_|1
Strings Metadata Strings Metadata
0|mpeg2video|0|video|1/25|[0][0][0][0]|0x0000|720|608|0|0|0|0|1:1|45:38|yuv422p|5|tv|unknown|unknown|unknown|topleft|tt|N/A|1|N/A|25/1|25/1|1/25|0|0.000000|N/A|N/A|30000000|N/A|N/A|N/A|N/A|35|0|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001300000000000000000000000000000000000001 0|mpeg2video|0|video|1/25|[0][0][0][0]|0x0000|720|608|0|0|0|0|1:1|45:38|yuv422p|5|tv|unknown|unknown|unknown|topleft|tb|N/A|1|N/A|25/1|25/1|1/25|0|0.000000|N/A|N/A|30000000|N/A|N/A|N/A|N/A|35|0|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001300000000000000000000000000000000000001
1|pcm_s16le|unknown|audio|1/48000|[0][0][0][0]|0x0000|s16|48000|2|unknown|16|N/A|0/0|0/0|1/48000|0|0.000000|N/A|N/A|1536000|N/A|N/A|N/A|N/A|35|0|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001300000000000000000000000000000000000001 1|pcm_s16le|unknown|audio|1/48000|[0][0][0][0]|0x0000|s16|48000|2|unknown|16|N/A|0/0|0/0|1/48000|0|0.000000|N/A|N/A|1536000|N/A|N/A|N/A|N/A|35|0|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001300000000000000000000000000000000000001

View File

@ -1,5 +1,5 @@
fdc02d700dbe99315a9f0d928a9b935e *tests/data/fate/rgb24-mkv.matroska fde8903c4df0ba8235dafcfd8a2f368c *tests/data/fate/rgb24-mkv.matroska
58213 tests/data/fate/rgb24-mkv.matroska 58216 tests/data/fate/rgb24-mkv.matroska
#tb 0: 1/10 #tb 0: 1/10
#media_type 0: video #media_type 0: video
#codec_id 0: rawvideo #codec_id 0: rawvideo

View File

@ -1,3 +1,3 @@
36fc2a640368f6d33987d2b2d39df966 *tests/data/lavf/lavf.mxf_d10 da0ebbebb50a530b14c0f06017f464b3 *tests/data/lavf/lavf.mxf_d10
5332013 tests/data/lavf/lavf.mxf_d10 5332013 tests/data/lavf/lavf.mxf_d10
tests/data/lavf/lavf.mxf_d10 CRC=0x6c74d488 tests/data/lavf/lavf.mxf_d10 CRC=0x6c74d488