X-Git-Url: https://git.cinelerra-gg.org/git/?p=goodguy%2Fcinelerra.git;a=blobdiff_plain;f=cinelerra-5.1%2Fcinelerra%2Fffmpeg.h;h=18516d3611c1bd5a6116698a290622ca8e477f75;hp=ec17c9b2cdb60974c4e3425b12cbb5cdbc7bc8ef;hb=c9c0e07706fad701a70ee0d1ffb0fcb6304f138c;hpb=5a46f81a504562b7c8a0c4ff940e2b5b5c068ded diff --git a/cinelerra-5.1/cinelerra/ffmpeg.h b/cinelerra-5.1/cinelerra/ffmpeg.h index ec17c9b2..18516d36 100644 --- a/cinelerra-5.1/cinelerra/ffmpeg.h +++ b/cinelerra-5.1/cinelerra/ffmpeg.h @@ -20,6 +20,7 @@ #include "fileffmpeg.inc" #include "indexstate.inc" #include "mutex.h" +#include "preferences.inc" #include "thread.h" #include "vframe.inc" @@ -36,6 +37,8 @@ extern "C" { #include "libavutil/pixdesc.h" #include "libswresample/swresample.h" #include "libswscale/swscale.h" +#include "libavutil/parseutils.h" +#include "libavutil/timecode.h" } class FFPacket { @@ -68,6 +71,7 @@ public: int initted() { return init; } void queue(int64_t pos); void dequeue(); + void set_hw_frame(AVFrame *frame); }; class FFStream { @@ -81,6 +85,8 @@ public: virtual int encode_activate(); virtual int decode_activate(); + virtual AVHWDeviceType decode_hw_activate(); + virtual int decode_hw_format(AVCodec *decoder, AVHWDeviceType type); virtual int write_packet(FFPacket &pkt); int read_packet(); int seek(int64_t no, double rate); @@ -115,6 +121,7 @@ public: AVFilterContext *buffersrc_ctx; AVFilterGraph *filter_graph; AVFrame *frame, *fframe; + AVFrame *probe_frame; AVBSFContext *bsfc; FFPacket ipkt; @@ -130,6 +137,9 @@ public: int reading, writing; int seeked, eof; + int hw_pixfmt; + AVBufferRef *hw_device_ctx; + FILE *stats_fp; char *stats_filename; char *stats_in; @@ -198,10 +208,18 @@ public: class FFVideoConvert { public: + Preferences *preferences; struct SwsContext *convert_ctx; + AVFrame *sw_frame; - FFVideoConvert() { convert_ctx = 0; } - ~FFVideoConvert() { if( convert_ctx ) sws_freeContext(convert_ctx); } + FFVideoConvert(Preferences *preferences) { + this->preferences = preferences; + convert_ctx = 0; sw_frame = 0; + } + ~FFVideoConvert() { + if( convert_ctx ) sws_freeContext(convert_ctx); + if( sw_frame ) av_frame_free(&sw_frame); + } static AVPixelFormat color_model_to_pix_fmt(int color_model); static int pix_fmt_to_color_model(AVPixelFormat pix_fmt); @@ -224,6 +242,10 @@ public: int is_audio() { return 0; } int is_video() { return 1; } int decode_frame(AVFrame *frame); + AVHWDeviceType decode_hw_activate(); + int decode_hw_format(AVCodec *decoder, AVHWDeviceType type); + AVHWDeviceType encode_hw_activate(const char *hw_dev); + int encode_hw_write(FFrame *picture); int encode_frame(AVFrame *frame); int create_filter(const char *filter_spec, AVCodecParameters *avpar); void load_markers(); @@ -234,17 +256,68 @@ public: int video_seek(int64_t pos); int encode(VFrame *vframe); int drain(); + double get_rotation_angle(); + void flip(); int idx; double frame_rate; - int width, height; + int width, height, transpose; int64_t length; float aspect_ratio; int interlaced; int top_field_first; + int color_space, color_range; +}; + +class FFCodecRemap +{ +public: + FFCodecRemap(); + ~FFCodecRemap(); + const char *old_codec, *new_codec; +}; + +class FFCodecRemaps : public ArrayList +{ +public: + FFCodecRemaps() {} + int add(const char *val); + int update(AVCodecID &codec_id, AVCodec *&decoder); +}; + +// for get_initial_timecode auto deletes +class avFrame { + AVFrame *frm; +public: + avFrame() { frm = av_frame_alloc(); } + ~avFrame() { av_frame_free(&frm); } + operator AVFrame *() { return frm; } + AVFrame *operator ->() { return frm; } +}; + +class avPacket { + AVPacket pkt; +public: + avPacket() { + av_init_packet(&pkt); + pkt.data = 0; pkt.size = 0; + } + ~avPacket() { av_packet_unref(&pkt); } + operator AVPacket *() { return &pkt; } + AVPacket *operator ->() { return &pkt; } }; +class avCodecContext { + AVCodecContext *avctx; +public: + avCodecContext(AVCodecContext *ctx) { avctx = ctx; } + ~avCodecContext() { avcodec_free_context(&avctx); } + operator AVCodecContext *() { return avctx; } + AVCodecContext *operator ->() { return avctx; } +}; + + class FFMPEG : public Thread { public: static Mutex fflock; @@ -252,7 +325,7 @@ public: static void ff_unlock() { fflock.unlock(); } int check_sample_rate(AVCodec *codec, int sample_rate); - AVRational check_frame_rate(AVCodec *codec, double frame_rate); + AVRational check_frame_rate(const AVRational *p, double frame_rate); AVRational to_sample_aspect_ratio(Asset *asset); AVRational to_time_base(int sample_rate); static int get_fmt_score(AVSampleFormat dst_fmt, AVSampleFormat src_fmt); @@ -274,6 +347,8 @@ public: static void load_audio_options(Asset *asset, EDL *edl); static void scan_video_options(Asset *asset, EDL *edl); static void load_video_options(Asset *asset, EDL *edl); + static void scan_format_options(Asset *asset, EDL *edl); + static void load_format_options(Asset *asset, EDL *edl); static void set_asset_format(Asset *asset, EDL *edl, const char *text); int get_file_format(); static int get_encoder(const char *options, char *format, char *codec, char *bsfilter); @@ -295,6 +370,7 @@ public: int total_audio_channels(); int total_video_channels(); + double get_initial_timecode(int data_type, int channel, double frame_rate); int audio_seek(int ch, int64_t pos); int video_seek(int layer, int64_t pos); @@ -314,6 +390,11 @@ public: double opt_duration; char *opt_video_filter; char *opt_audio_filter; + char *opt_hw_dev; + char *opt_video_decoder; + char *opt_audio_decoder; + FFCodecRemaps video_codec_remaps; + FFCodecRemaps audio_codec_remaps; char file_format[BCTEXTLEN]; int fflags; @@ -346,6 +427,7 @@ public: FFMPEG(FileBase *file_base=0); ~FFMPEG(); + AVCodecContext *activate_decoder(AVStream *st); int scan(IndexState *index_state, int64_t *scan_position, int *canceled); int ff_audio_stream(int channel) { return astrm_index[channel].st_idx; } @@ -369,13 +451,19 @@ public: int ff_coded_width(int stream); int ff_coded_height(int stream); float ff_aspect_ratio(int stream); + int ff_color_range(int stream); + int ff_color_space(int stream); double ff_frame_rate(int stream); - const char *ff_video_format(int stream); + const char *ff_video_codec(int stream); int64_t ff_video_frames(int stream); int ff_video_pid(int stream); int ff_video_mpeg_color_range(int stream); + double ff_get_timecode(char *str, AVRational rate, double pos); + static double get_timecode(const char *path, int data_type, int channel, double rate); int ff_cpus(); + const char *ff_hw_dev(); + Preferences *ff_prefs(); void dump_context(AVCodecContext *ctx); };