You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-07-06 06:27:36 +02:00
Merge remote-tracking branch 'cigaes/master'
* cigaes/master: ffmpeg: make -aspect work with -vcodec copy. lavfi/vf_aspect: improve compatibility of parsing. Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
@ -468,6 +468,10 @@ form @var{num}:@var{den}, where @var{num} and @var{den} are the
|
|||||||
numerator and denominator of the aspect ratio. For example "4:3",
|
numerator and denominator of the aspect ratio. For example "4:3",
|
||||||
"16:9", "1.3333", and "1.7777" are valid argument values.
|
"16:9", "1.3333", and "1.7777" are valid argument values.
|
||||||
|
|
||||||
|
If used together with @option{-vcodec copy}, it will affect the aspect ratio
|
||||||
|
stored at container level, but not the aspect ratio stored in encoded
|
||||||
|
frames, if it exists.
|
||||||
|
|
||||||
@item -vn (@emph{output})
|
@item -vn (@emph{output})
|
||||||
Disable video recording.
|
Disable video recording.
|
||||||
|
|
||||||
|
9
ffmpeg.c
9
ffmpeg.c
@ -2224,7 +2224,14 @@ static int transcode_init(void)
|
|||||||
codec->width = icodec->width;
|
codec->width = icodec->width;
|
||||||
codec->height = icodec->height;
|
codec->height = icodec->height;
|
||||||
codec->has_b_frames = icodec->has_b_frames;
|
codec->has_b_frames = icodec->has_b_frames;
|
||||||
if (!codec->sample_aspect_ratio.num) {
|
if (ost->frame_aspect_ratio.num) { // overridden by the -aspect cli option
|
||||||
|
codec->sample_aspect_ratio =
|
||||||
|
ost->st->sample_aspect_ratio =
|
||||||
|
av_mul_q(ost->frame_aspect_ratio,
|
||||||
|
(AVRational){ codec->height, codec->width });
|
||||||
|
av_log(NULL, AV_LOG_WARNING, "Overriding aspect ratio "
|
||||||
|
"with stream copy may produce invalid files\n");
|
||||||
|
} else if (!codec->sample_aspect_ratio.num) {
|
||||||
codec->sample_aspect_ratio =
|
codec->sample_aspect_ratio =
|
||||||
ost->st->sample_aspect_ratio =
|
ost->st->sample_aspect_ratio =
|
||||||
ist->st->sample_aspect_ratio.num ? ist->st->sample_aspect_ratio :
|
ist->st->sample_aspect_ratio.num ? ist->st->sample_aspect_ratio :
|
||||||
|
30
ffmpeg_opt.c
30
ffmpeg_opt.c
@ -1168,7 +1168,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in
|
|||||||
AVStream *st;
|
AVStream *st;
|
||||||
OutputStream *ost;
|
OutputStream *ost;
|
||||||
AVCodecContext *video_enc;
|
AVCodecContext *video_enc;
|
||||||
char *frame_rate = NULL;
|
char *frame_rate = NULL, *frame_aspect_ratio = NULL;
|
||||||
|
|
||||||
ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO, source_index);
|
ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO, source_index);
|
||||||
st = ost->st;
|
st = ost->st;
|
||||||
@ -1180,20 +1180,6 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ost->stream_copy) {
|
|
||||||
const char *p = NULL;
|
|
||||||
char *frame_size = NULL;
|
|
||||||
char *frame_aspect_ratio = NULL, *frame_pix_fmt = NULL;
|
|
||||||
char *intra_matrix = NULL, *inter_matrix = NULL;
|
|
||||||
int do_pass = 0;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, oc, st);
|
|
||||||
if (frame_size && av_parse_video_size(&video_enc->width, &video_enc->height, frame_size) < 0) {
|
|
||||||
av_log(NULL, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
MATCH_PER_STREAM_OPT(frame_aspect_ratios, str, frame_aspect_ratio, oc, st);
|
MATCH_PER_STREAM_OPT(frame_aspect_ratios, str, frame_aspect_ratio, oc, st);
|
||||||
if (frame_aspect_ratio) {
|
if (frame_aspect_ratio) {
|
||||||
AVRational q;
|
AVRational q;
|
||||||
@ -1205,6 +1191,20 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in
|
|||||||
ost->frame_aspect_ratio = q;
|
ost->frame_aspect_ratio = q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ost->stream_copy) {
|
||||||
|
const char *p = NULL;
|
||||||
|
char *frame_size = NULL;
|
||||||
|
char *frame_pix_fmt = NULL;
|
||||||
|
char *intra_matrix = NULL, *inter_matrix = NULL;
|
||||||
|
int do_pass = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, oc, st);
|
||||||
|
if (frame_size && av_parse_video_size(&video_enc->width, &video_enc->height, frame_size) < 0) {
|
||||||
|
av_log(NULL, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
video_enc->bits_per_raw_sample = frame_bits_per_raw_sample;
|
video_enc->bits_per_raw_sample = frame_bits_per_raw_sample;
|
||||||
MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st);
|
MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st);
|
||||||
if (frame_pix_fmt && *frame_pix_fmt == '+') {
|
if (frame_pix_fmt && *frame_pix_fmt == '+') {
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#include <float.h>
|
#include <float.h>
|
||||||
|
|
||||||
#include "libavutil/common.h"
|
#include "libavutil/common.h"
|
||||||
#include "libavutil/opt.h"
|
#include "libavutil/eval.h"
|
||||||
#include "libavutil/mathematics.h"
|
#include "libavutil/mathematics.h"
|
||||||
#include "libavutil/opt.h"
|
#include "libavutil/opt.h"
|
||||||
#include "libavutil/parseutils.h"
|
#include "libavutil/parseutils.h"
|
||||||
@ -40,7 +40,7 @@ typedef struct {
|
|||||||
AVRational aspect;
|
AVRational aspect;
|
||||||
int max;
|
int max;
|
||||||
#if FF_API_OLD_FILTER_OPTS
|
#if FF_API_OLD_FILTER_OPTS
|
||||||
float aspect_num, aspect_den;
|
float aspect_den;
|
||||||
#endif
|
#endif
|
||||||
char *ratio_str;
|
char *ratio_str;
|
||||||
} AspectContext;
|
} AspectContext;
|
||||||
@ -51,10 +51,17 @@ static av_cold int init(AVFilterContext *ctx)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
#if FF_API_OLD_FILTER_OPTS
|
#if FF_API_OLD_FILTER_OPTS
|
||||||
if (s->aspect_num > 0 && s->aspect_den > 0) {
|
if (s->ratio_str && s->aspect_den > 0) {
|
||||||
|
double num;
|
||||||
av_log(ctx, AV_LOG_WARNING,
|
av_log(ctx, AV_LOG_WARNING,
|
||||||
"num:den syntax is deprecated, please use num/den or named options instead\n");
|
"num:den syntax is deprecated, please use num/den or named options instead\n");
|
||||||
s->aspect = av_d2q(s->aspect_num / s->aspect_den, s->max);
|
ret = av_expr_parse_and_eval(&num, s->ratio_str, NULL, NULL,
|
||||||
|
NULL, NULL, NULL, NULL, NULL, 0, ctx);
|
||||||
|
if (ret < 0) {
|
||||||
|
av_log(ctx, AV_LOG_ERROR, "Unable to parse ratio numerator \"%s\"\n", s->ratio_str);
|
||||||
|
return AVERROR(EINVAL);
|
||||||
|
}
|
||||||
|
s->aspect = av_d2q(num / s->aspect_den, s->max);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
if (s->ratio_str) {
|
if (s->ratio_str) {
|
||||||
@ -115,13 +122,12 @@ static int setdar_config_props(AVFilterLink *inlink)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const AVOption setdar_options[] = {
|
static const AVOption setdar_options[] = {
|
||||||
#if FF_API_OLD_FILTER_OPTS
|
|
||||||
{ "dar_num", NULL, OFFSET(aspect_num), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, FLT_MAX, FLAGS },
|
|
||||||
{ "dar_den", NULL, OFFSET(aspect_den), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, FLT_MAX, FLAGS },
|
|
||||||
#endif
|
|
||||||
{ "dar", "set display aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, .flags=FLAGS },
|
{ "dar", "set display aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, .flags=FLAGS },
|
||||||
{ "ratio", "set display aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, .flags=FLAGS },
|
{ "ratio", "set display aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, .flags=FLAGS },
|
||||||
{ "r", "set display aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, .flags=FLAGS },
|
{ "r", "set display aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, .flags=FLAGS },
|
||||||
|
#if FF_API_OLD_FILTER_OPTS
|
||||||
|
{ "dar_den", NULL, OFFSET(aspect_den), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, FLT_MAX, FLAGS },
|
||||||
|
#endif
|
||||||
{ "max", "set max value for nominator or denominator in the ratio", OFFSET(max), AV_OPT_TYPE_INT, {.i64=100}, 1, INT_MAX, FLAGS },
|
{ "max", "set max value for nominator or denominator in the ratio", OFFSET(max), AV_OPT_TYPE_INT, {.i64=100}, 1, INT_MAX, FLAGS },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
@ -181,13 +187,12 @@ static int setsar_config_props(AVFilterLink *inlink)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const AVOption setsar_options[] = {
|
static const AVOption setsar_options[] = {
|
||||||
#if FF_API_OLD_FILTER_OPTS
|
|
||||||
{ "sar_num", NULL, OFFSET(aspect_num), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, FLT_MAX, FLAGS },
|
|
||||||
{ "sar_den", NULL, OFFSET(aspect_den), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, FLT_MAX, FLAGS },
|
|
||||||
#endif
|
|
||||||
{ "sar", "set sample (pixel) aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, .flags=FLAGS },
|
{ "sar", "set sample (pixel) aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, .flags=FLAGS },
|
||||||
{ "ratio", "set sample (pixel) aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, .flags=FLAGS },
|
{ "ratio", "set sample (pixel) aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, .flags=FLAGS },
|
||||||
{ "r", "set sample (pixel) aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, .flags=FLAGS },
|
{ "r", "set sample (pixel) aspect ratio", OFFSET(ratio_str), AV_OPT_TYPE_STRING, {.str="0"}, .flags=FLAGS },
|
||||||
|
#if FF_API_OLD_FILTER_OPTS
|
||||||
|
{ "sar_den", NULL, OFFSET(aspect_den), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, FLT_MAX, FLAGS },
|
||||||
|
#endif
|
||||||
{ "max", "set max value for nominator or denominator in the ratio", OFFSET(max), AV_OPT_TYPE_INT, {.i64=100}, 1, INT_MAX, FLAGS },
|
{ "max", "set max value for nominator or denominator in the ratio", OFFSET(max), AV_OPT_TYPE_INT, {.i64=100}, 1, INT_MAX, FLAGS },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user