rest of Termux related mods from Andrew
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / ffmpeg.C
index 90e4a8510421a5c4bdf60d44422dc5245d0e29f9..3655d643fb097f4f954c768aeabf26bef44e6e60 100644 (file)
@@ -29,7 +29,9 @@
 #include "ffmpeg.h"
 #include "indexfile.h"
 #include "interlacemodes.h"
+#ifdef HAVE_DV
 #include "libdv.h"
+#endif
 #include "libmjpeg.h"
 #include "mainerror.h"
 #include "mwindow.h"
@@ -603,6 +605,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;
@@ -1243,6 +1246,7 @@ int FFVideoStream::probe(int64_t pos)
                ret = -1;
 
        ret = ret > 0 ? 1 : ret < 0 ? -1 : 0;
+       av_frame_free(&frame);
        return ret;
 }
 
@@ -1589,9 +1593,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 +1724,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);
 
@@ -2638,18 +2646,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;
                        }
@@ -2892,9 +2904,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 ) {