From 143d6a3fa79f2d8b230c02939e3d8bbdbbacb25a Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sun, 17 Jul 2011 13:28:42 +0000 Subject: [PATCH 1/8] lavc: add A|E|D flags to "ac" and "ar" options Fix setting of the corresponding AVCodecContext fields via cmdutils.c:filter_codec_opts(). In particular, fix ffplay -ac and -ar options. Signed-off-by: Anton Khirnov --- libavcodec/options.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/options.c b/libavcodec/options.c index f19928cd86..821bf800b3 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -126,8 +126,8 @@ static const AVOption options[]={ {"extradata_size", NULL, OFFSET(extradata_size), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, {"time_base", NULL, OFFSET(time_base), FF_OPT_TYPE_RATIONAL, {.dbl = 0}, INT_MIN, INT_MAX}, {"g", "set the group of picture size", OFFSET(gop_size), FF_OPT_TYPE_INT, {.dbl = 12 }, INT_MIN, INT_MAX, V|E}, -{"ar", "set audio sampling rate (in Hz)", OFFSET(sample_rate), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, -{"ac", "set number of audio channels", OFFSET(channels), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, +{"ar", "set audio sampling rate (in Hz)", OFFSET(sample_rate), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|D|E}, +{"ac", "set number of audio channels", OFFSET(channels), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|D|E}, {"cutoff", "set cutoff bandwidth", OFFSET(cutoff), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|E}, {"frame_size", NULL, OFFSET(frame_size), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|E}, {"frame_number", NULL, OFFSET(frame_number), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, From b6d28eff8454dd37c2f461fa7c55e35be7b05e9c Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sun, 21 Aug 2011 16:20:37 +0200 Subject: [PATCH 2/8] avplay: add examples of how to specify size/pixel format through private options Clarify with an example what the user should use instead of the deprecated (and no longer working) -s/-pix_fmt options. Signed-off-by: Anton Khirnov --- doc/avplay.texi | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/avplay.texi b/doc/avplay.texi index d7fecf0db0..e292481228 100644 --- a/doc/avplay.texi +++ b/doc/avplay.texi @@ -39,7 +39,8 @@ Force displayed width. Force displayed height. @item -s @var{size} This option has been removed. Use private format options for specifying the -input video size. +input video size. For example with the rawvideo demuxer you need to specify the +option @var{video_size}. @item -an Disable audio. @item -vn @@ -70,7 +71,8 @@ also sources and sinks). @table @option @item -pix_fmt @var{format} This option has been removed. Use private options for specifying the -input pixel format. +input pixel format. For example with the rawvideo demuxer you need to specify +the option @var{pixel_format}. @item -stats Show the stream duration, the codec parameters, the current position in the stream and the audio/video synchronisation drift. From 3436c4a368aca1bdcbf28bdfc996903460263de0 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 20 Aug 2011 16:02:22 +0200 Subject: [PATCH 3/8] matroskaenc: saner default codecs. libvorbis/libx264 for video if available, otherwise ac3/mpeg4. --- libavformat/matroskaenc.c | 16 ++++++++++++++-- tests/lavf-regression.sh | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index aa767f3535..ce1a7d1d3f 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -1214,8 +1214,16 @@ AVOutputFormat ff_matroska_muxer = { .mime_type = "video/x-matroska", .extensions = "mkv", .priv_data_size = sizeof(MatroskaMuxContext), - .audio_codec = CODEC_ID_MP2, +#if CONFIG_LIBVORBIS_ENCODER + .audio_codec = CODEC_ID_VORBIS, +#else + .audio_codec = CODEC_ID_AC3, +#endif +#if CONFIG_LIBX264_ENCODER + .video_codec = CODEC_ID_H264, +#else .video_codec = CODEC_ID_MPEG4, +#endif .write_header = mkv_write_header, .write_packet = mkv_write_packet, .write_trailer = mkv_write_trailer, @@ -1249,7 +1257,11 @@ AVOutputFormat ff_matroska_audio_muxer = { .mime_type = "audio/x-matroska", .extensions = "mka", .priv_data_size = sizeof(MatroskaMuxContext), - .audio_codec = CODEC_ID_MP2, +#if CONFIG_LIBVORBIS_ENCODER + .audio_codec = CODEC_ID_VORBIS, +#else + .audio_codec = CODEC_ID_AC3, +#endif .video_codec = CODEC_ID_NONE, .write_header = mkv_write_header, .write_packet = mkv_write_packet, diff --git a/tests/lavf-regression.sh b/tests/lavf-regression.sh index 859ccb946e..a3a0b86b96 100755 --- a/tests/lavf-regression.sh +++ b/tests/lavf-regression.sh @@ -103,7 +103,7 @@ do_lavf nut "-acodec mp2" fi if [ -n "$do_mkv" ] ; then -do_lavf mkv +do_lavf mkv "-c:a mp2 -c:v mpeg4" fi From b71389cbaee037f90ddaf4f7e8892a17831e860e Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 20 Aug 2011 16:05:17 +0200 Subject: [PATCH 4/8] avienc: saner default audio codec. libmp3lame if available, ac3 otherwise. --- libavformat/avienc.c | 6 +++++- tests/lavf-regression.sh | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libavformat/avienc.c b/libavformat/avienc.c index 1dbed8bc80..cf2e1d601d 100644 --- a/libavformat/avienc.c +++ b/libavformat/avienc.c @@ -644,7 +644,11 @@ AVOutputFormat ff_avi_muxer = { .mime_type = "video/x-msvideo", .extensions = "avi", .priv_data_size = sizeof(AVIContext), - .audio_codec = CODEC_ID_MP2, +#if CONFIG_LIBMP3LAME_ENCODER + .audio_codec = CODEC_ID_MP3, +#else + .audio_codec = CODEC_ID_AC3, +#endif .video_codec = CODEC_ID_MPEG4, .write_header = avi_write_header, .write_packet = avi_write_packet, diff --git a/tests/lavf-regression.sh b/tests/lavf-regression.sh index a3a0b86b96..8ed92771d0 100755 --- a/tests/lavf-regression.sh +++ b/tests/lavf-regression.sh @@ -44,7 +44,7 @@ do_audio_only() } if [ -n "$do_avi" ] ; then -do_lavf avi +do_lavf avi "-acodec mp2" fi if [ -n "$do_asf" ] ; then From fb42d156ed3a726f9a6c76025ea9e1237e6b4840 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 20 Aug 2011 16:14:58 +0200 Subject: [PATCH 5/8] movenc: use libx264 by default when possible for mov, mp4 and psp --- libavformat/movenc.c | 12 ++++++++++++ tests/lavf-regression.sh | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 03959106c5..5ac95b804d 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -2343,7 +2343,11 @@ AVOutputFormat ff_mov_muxer = { .extensions = "mov", .priv_data_size = sizeof(MOVMuxContext), .audio_codec = CODEC_ID_AAC, +#if CONFIG_LIBX264_ENCODER + .video_codec = CODEC_ID_H264, +#else .video_codec = CODEC_ID_MPEG4, +#endif .write_header = mov_write_header, .write_packet = ff_mov_write_packet, .write_trailer = mov_write_trailer, @@ -2376,7 +2380,11 @@ AVOutputFormat ff_mp4_muxer = { .extensions = "mp4", .priv_data_size = sizeof(MOVMuxContext), .audio_codec = CODEC_ID_AAC, +#if CONFIG_LIBX264_ENCODER + .video_codec = CODEC_ID_H264, +#else .video_codec = CODEC_ID_MPEG4, +#endif .write_header = mov_write_header, .write_packet = ff_mov_write_packet, .write_trailer = mov_write_trailer, @@ -2392,7 +2400,11 @@ AVOutputFormat ff_psp_muxer = { .extensions = "mp4,psp", .priv_data_size = sizeof(MOVMuxContext), .audio_codec = CODEC_ID_AAC, +#if CONFIG_LIBX264_ENCODER + .video_codec = CODEC_ID_H264, +#else .video_codec = CODEC_ID_MPEG4, +#endif .write_header = mov_write_header, .write_packet = ff_mov_write_packet, .write_trailer = mov_write_trailer, diff --git a/tests/lavf-regression.sh b/tests/lavf-regression.sh index 8ed92771d0..1d7f640124 100755 --- a/tests/lavf-regression.sh +++ b/tests/lavf-regression.sh @@ -87,7 +87,7 @@ do_lavf flv -an fi if [ -n "$do_mov" ] ; then -do_lavf mov "-acodec pcm_alaw" +do_lavf mov "-acodec pcm_alaw -c:v mpeg4" fi if [ -n "$do_dv_fmt" ] ; then From 0a593de38aa02d752eb44cfbe2d6cd4595a8c059 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 20 Aug 2011 16:20:27 +0200 Subject: [PATCH 6/8] mp2 encoder: make 128k the default bitrate. --- libavcodec/mpegaudioenc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libavcodec/mpegaudioenc.c b/libavcodec/mpegaudioenc.c index 96c0fec445..1cadef7175 100644 --- a/libavcodec/mpegaudioenc.c +++ b/libavcodec/mpegaudioenc.c @@ -25,6 +25,7 @@ */ #include "avcodec.h" +#include "internal.h" #include "put_bits.h" #define FRAC_BITS 15 /* fractional bits for sb_samples and dct */ @@ -759,6 +760,11 @@ static av_cold int MPA_encode_close(AVCodecContext *avctx) return 0; } +static const AVCodecDefault mp2_defaults[] = { + { "b", "128k" }, + { NULL }, +}; + AVCodec ff_mp2_encoder = { .name = "mp2", .type = AVMEDIA_TYPE_AUDIO, @@ -770,4 +776,5 @@ AVCodec ff_mp2_encoder = { .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, .supported_samplerates= (const int[]){44100, 48000, 32000, 22050, 24000, 16000, 0}, .long_name = NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"), + .defaults = mp2_defaults, }; From 03eff2bf430a1d80e0854dfd58c8b353f774edde Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 20 Aug 2011 16:47:36 +0200 Subject: [PATCH 7/8] libx264: use medium preset by default. --- libavcodec/libx264.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index fea67f164a..50688fd3ef 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -362,7 +362,7 @@ static av_cold int X264_init(AVCodecContext *avctx) #define OFFSET(x) offsetof(X264Context, x) #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { - { "preset", "Set the encoding preset (cf. x264 --fullhelp)", OFFSET(preset), FF_OPT_TYPE_STRING, { 0 }, 0, 0, VE}, + { "preset", "Set the encoding preset (cf. x264 --fullhelp)", OFFSET(preset), FF_OPT_TYPE_STRING, { .str = "medium" }, 0, 0, VE}, { "tune", "Tune the encoding params (cf. x264 --fullhelp)", OFFSET(tune), FF_OPT_TYPE_STRING, { 0 }, 0, 0, VE}, { "profile", "Set profile restrictions (cf. x264 --fullhelp) ", OFFSET(profile), FF_OPT_TYPE_STRING, { 0 }, 0, 0, VE}, { "fastfirstpass", "Use fast settings when encoding first pass", OFFSET(fastfirstpass), FF_OPT_TYPE_INT, { 1 }, 0, 1, VE}, From ae60927aefe7a9debc285451b2badf1b8eb5ab22 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 20 Aug 2011 16:59:47 +0200 Subject: [PATCH 8/8] libx264: only use ABR mode when the user explicitly set bitrate. --- libavcodec/libx264.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 50688fd3ef..44c85fdef6 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -21,6 +21,7 @@ #include "libavutil/opt.h" #include "avcodec.h" +#include "internal.h" #include #include #include @@ -263,7 +264,10 @@ static av_cold int X264_init(AVCodecContext *avctx) x4->params.i_log_level = X264_LOG_DEBUG; x4->params.b_intra_refresh = avctx->flags2 & CODEC_FLAG2_INTRA_REFRESH; - x4->params.rc.i_bitrate = avctx->bit_rate / 1000; + if (avctx->bit_rate) { + x4->params.rc.i_bitrate = avctx->bit_rate / 1000; + x4->params.rc.i_rc_method = X264_RC_ABR; + } x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000; x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000; x4->params.rc.b_stat_write = avctx->flags & CODEC_FLAG_PASS1; @@ -280,11 +284,6 @@ static av_cold int X264_init(AVCodecContext *avctx) } } - // if neither crf nor cqp modes are selected we have to enable the RC - // we do it this way because we cannot check if the bitrate has been set - if (!(avctx->crf || (avctx->cqp > -1))) - x4->params.rc.i_rc_method = X264_RC_ABR; - if (avctx->rc_buffer_size && avctx->rc_initial_buffer_occupancy && (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)) { x4->params.rc.f_vbv_buffer_init = @@ -376,6 +375,11 @@ static const AVClass class = { .version = LIBAVUTIL_VERSION_INT, }; +static const AVCodecDefault x264_defaults[] = { + { "b", "0" }, + { NULL }, +}; + AVCodec ff_libx264_encoder = { .name = "libx264", .type = AVMEDIA_TYPE_VIDEO, @@ -388,4 +392,5 @@ AVCodec ff_libx264_encoder = { .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_YUV420P, PIX_FMT_YUVJ420P, PIX_FMT_NONE }, .long_name = NULL_IF_CONFIG_SMALL("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"), .priv_class = &class, + .defaults = x264_defaults, };