[FFmpeg-devel] [PATCH 5/6] fftools/ffmpeg: support applying container level cropping
Anton Khirnov
anton at khirnov.net
Tue Jun 25 13:19:42 EEST 2024
Quoting James Almer (2024-05-29 23:46:31)
> @@ -254,6 +256,11 @@ typedef struct InputFilterOptions {
> * accurate */
> AVRational framerate;
>
> + unsigned crop_top;
> + unsigned crop_bottom;
> + unsigned crop_left;
> + unsigned crop_right;
breaks vertical alignment
> +
> int sub2video_width;
> int sub2video_height;
>
> diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
> index 1ca8d804ae..4178b8f840 100644
> --- a/fftools/ffmpeg_demux.c
> +++ b/fftools/ffmpeg_demux.c
> @@ -66,6 +66,7 @@ typedef struct DemuxStream {
> int have_sub2video;
> int reinit_filters;
> int autorotate;
> + int apply_cropping;
>
>
> int wrap_correction_done;
> @@ -1000,11 +1001,20 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple,
> ist->filters[ist->nb_filters - 1] = ifilter;
>
> if (ist->par->codec_type == AVMEDIA_TYPE_VIDEO) {
> + const AVPacketSideData *sd = av_packet_side_data_get(ist->st->codecpar->coded_side_data,
> + ist->st->codecpar->nb_coded_side_data,
> + AV_PKT_DATA_FRAME_CROPPING);
> if (ist->framerate.num > 0 && ist->framerate.den > 0) {
> opts->framerate = ist->framerate;
> opts->flags |= IFILTER_FLAG_CFR;
> } else
> opts->framerate = av_guess_frame_rate(d->f.ctx, ist->st, NULL);
> + if (sd && sd->size == sizeof(uint32_t) * 4) {
better make it <= to account for future extensions, e.g. we might want
to add sub-pixel resolution in there
> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
> index 910e4a336b..0c50ce16ba 100644
> --- a/fftools/ffmpeg_opt.c
> +++ b/fftools/ffmpeg_opt.c
> @@ -1732,6 +1732,9 @@ const OptionDef options[] = {
> { "autoscale", OPT_TYPE_BOOL, OPT_PERSTREAM | OPT_EXPERT | OPT_OUTPUT,
> { .off = OFFSET(autoscale) },
> "automatically insert a scale filter at the end of the filter graph" },
> + { "apply_cropping", OPT_TYPE_BOOL, OPT_PERSTREAM | OPT_EXPERT | OPT_INPUT,
> + { .off = OFFSET(apply_cropping) },
> + "apply frame cropping" },
Apply container-level cropping (in addition to codec-level cropping)
Also, missing docs.
--
Anton Khirnov
More information about the ffmpeg-devel
mailing list