X-Git-Url: https://git.cinelerra-gg.org/git/?p=goodguy%2Fcinelerra.git;a=blobdiff_plain;f=cinelerra-5.1%2Fcinelerra%2Fffmpeg.C;h=b05a455d53add2d63de49a314239187ae9438dac;hp=df39763c3e30033db7c0d640d96d2d22a0c745f2;hb=b7045bda288a03559422862284a9cf411b63c072;hpb=97ed925c86313b57c13a2db0fb9aa48822fe76ba diff --git a/cinelerra-5.1/cinelerra/ffmpeg.C b/cinelerra-5.1/cinelerra/ffmpeg.C index df39763c..b05a455d 100644 --- a/cinelerra-5.1/cinelerra/ffmpeg.C +++ b/cinelerra-5.1/cinelerra/ffmpeg.C @@ -603,6 +603,7 @@ int FFStream::encode_frame(AVFrame *frame) ret = avcodec_send_frame(avctx, frame); if( !ret && frame ) return pkts; if( ret < 0 && ret != AVERROR(EAGAIN) ) break; + if ( ret == AVERROR(EAGAIN) && !frame ) continue; FFPacket opkt; ret = avcodec_receive_packet(avctx, opkt); if( !frame && ret == AVERROR_EOF ) return pkts; @@ -1589,9 +1590,11 @@ int FFVideoConvert::convert_picture_vframe(VFrame *frame, AVFrame *ip, AVFrame * } int color_space = SWS_CS_ITU601; switch( preferences->yuv_color_space ) { - case BC_COLORS_BT601: color_space = SWS_CS_ITU601; break; + case BC_COLORS_BT601_PAL: color_space = SWS_CS_ITU601; break; + case BC_COLORS_BT601_NTSC: color_space = SWS_CS_SMPTE170M; break; case BC_COLORS_BT709: color_space = SWS_CS_ITU709; break; - case BC_COLORS_BT2020: color_space = SWS_CS_BT2020; break; + case BC_COLORS_BT2020_NCL: + case BC_COLORS_BT2020_CL: color_space = SWS_CS_BT2020; break; } const int *color_table = sws_getCoefficients(color_space); @@ -1718,9 +1721,11 @@ int FFVideoConvert::convert_vframe_picture(VFrame *frame, AVFrame *op, AVFrame * } int color_space = SWS_CS_ITU601; switch( preferences->yuv_color_space ) { - case BC_COLORS_BT601: color_space = SWS_CS_ITU601; break; + case BC_COLORS_BT601_PAL: color_space = SWS_CS_ITU601; break; + case BC_COLORS_BT601_NTSC: color_space = SWS_CS_SMPTE170M; break; case BC_COLORS_BT709: color_space = SWS_CS_ITU709; break; - case BC_COLORS_BT2020: color_space = SWS_CS_BT2020; break; + case BC_COLORS_BT2020_NCL: + case BC_COLORS_BT2020_CL: color_space = SWS_CS_BT2020; break; } const int *color_table = sws_getCoefficients(color_space); @@ -1853,12 +1858,15 @@ int FFMPEG::check_sample_rate(AVCodec *codec, int sample_rate) return 0; } +// check_frame_rate and std_frame_rate needed for 23.976 +// and 59.94 fps mpeg2 static inline AVRational std_frame_rate(int i) { static const int m1 = 1001*12, m2 = 1000*12; static const int freqs[] = { 40*m1, 48*m1, 50*m1, 60*m1, 80*m1,120*m1, 240*m1, - 24*m2, 30*m2, 60*m2, 12*m2, 15*m2, 48*m2, 0, + 24*m2, 30*m2, 60*m2, 12*m2, 15*m2, 48*m2, 90*m2, + 100*m2, 120*m2, 144*m2, 72*m2, 0, }; int freq = i<30*12 ? (i+1)*1001 : freqs[i-30*12]; return (AVRational) { freq, 1001*12 }; @@ -2635,18 +2643,22 @@ int FFMPEG::open_decoder() } switch( avpar->color_space ) { case AVCOL_SPC_BT470BG: + vid->color_space = BC_COLORS_BT601_PAL; + break; case AVCOL_SPC_SMPTE170M: - vid->color_space = BC_COLORS_BT601; + vid->color_space = BC_COLORS_BT601_NTSC; break; case AVCOL_SPC_BT709: vid->color_space = BC_COLORS_BT709; break; case AVCOL_SPC_BT2020_NCL: + vid->color_space = BC_COLORS_BT2020_NCL; + break; case AVCOL_SPC_BT2020_CL: - vid->color_space = BC_COLORS_BT2020; + vid->color_space = BC_COLORS_BT2020_CL; break; default: - vid->color_space = !file_base ? BC_COLORS_BT601 : + vid->color_space = !file_base ? BC_COLORS_BT601_NTSC : file_base->file->preferences->yuv_color_space; break; } @@ -2889,9 +2901,11 @@ int FFMPEG::open_encoder(const char *type, const char *spec) if( (vid->color_space = asset->ff_color_space) < 0 ) vid->color_space = file_base->file->preferences->yuv_color_space; switch( vid->color_space ) { - case BC_COLORS_BT601: ctx->colorspace = AVCOL_SPC_SMPTE170M; break; + case BC_COLORS_BT601_NTSC: ctx->colorspace = AVCOL_SPC_SMPTE170M; break; + case BC_COLORS_BT601_PAL: ctx->colorspace = AVCOL_SPC_BT470BG; break; case BC_COLORS_BT709: ctx->colorspace = AVCOL_SPC_BT709; break; - case BC_COLORS_BT2020: ctx->colorspace = AVCOL_SPC_BT2020_NCL; break; + case BC_COLORS_BT2020_NCL: ctx->colorspace = AVCOL_SPC_BT2020_NCL; break; + case BC_COLORS_BT2020_CL: ctx->colorspace = AVCOL_SPC_BT2020_CL; break; } AVPixelFormat pix_fmt = av_get_pix_fmt(asset->ff_pixel_format); if( opt_hw_dev != 0 ) { @@ -2914,7 +2928,12 @@ int FFMPEG::open_encoder(const char *type, const char *spec) int mask_h = (1<log2_chroma_h)-1; ctx->height = (vid->height+mask_h) & ~mask_h; ctx->sample_aspect_ratio = to_sample_aspect_ratio(asset); - AVRational frame_rate = check_frame_rate(codec->supported_framerates, vid->frame_rate); + AVRational frame_rate; + if (ctx->codec->id == AV_CODEC_ID_MPEG1VIDEO || + ctx->codec->id == AV_CODEC_ID_MPEG2VIDEO) + frame_rate = check_frame_rate(codec->supported_framerates, vid->frame_rate); + else + frame_rate = av_d2q(vid->frame_rate, INT_MAX); if( !frame_rate.num || !frame_rate.den ) { eprintf(_("check_frame_rate failed %s\n"), filename); ret = 1;