avconv: make -t insert trim/atrim filters.

This makes -t sample-accurate for audio and will allow further
simplication in the future.

Most of the FATE changes are due to audio now being sample accurate. In
some cases a video frame was incorrectly passed with the old code, while
its was over the limit.
This commit is contained in:
Anton Khirnov 2013-04-10 15:02:01 +02:00
parent 3d62442008
commit a83c0da539
43 changed files with 127 additions and 77 deletions

View File

@ -14,6 +14,7 @@ version 10:
- JPEG 2000 decoder
- new asetpts filter (same as setpts, but for audio)
- new trim and atrim filters
- avconv -t option is now sample-accurate when transcoding audio
version 9:

View File

@ -380,9 +380,6 @@ static void do_audio_out(AVFormatContext *s, OutputStream *ost,
pkt.data = NULL;
pkt.size = 0;
if (!check_recording_time(ost))
return;
if (frame->pts == AV_NOPTS_VALUE || audio_sync_method < 0)
frame->pts = ost->sync_opts;
ost->sync_opts = frame->pts + frame->nb_samples;
@ -549,8 +546,7 @@ static void do_video_out(AVFormatContext *s,
pkt.data = NULL;
pkt.size = 0;
if (!check_recording_time(ost) ||
ost->frame_number >= ost->max_frames)
if (ost->frame_number >= ost->max_frames)
return;
if (s->oformat->flags & AVFMT_RAWPICTURE &&

View File

@ -173,6 +173,52 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
ist->filters[ist->nb_filters - 1] = fg->inputs[fg->nb_inputs - 1];
}
static int insert_trim(OutputStream *ost, AVFilterContext **last_filter, int *pad_idx)
{
OutputFile *of = output_files[ost->file_index];
AVFilterGraph *graph = (*last_filter)->graph;
AVFilterContext *ctx;
const AVFilter *trim;
const char *name = ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO ? "trim" : "atrim";
char filter_name[128];
int ret = 0;
if (of->recording_time == INT64_MAX)
return 0;
trim = avfilter_get_by_name(name);
if (!trim) {
av_log(NULL, AV_LOG_ERROR, "%s filter not present, cannot limit "
"recording time.\n", name);
return AVERROR_FILTER_NOT_FOUND;
}
snprintf(filter_name, sizeof(filter_name), "%s for output stream %d:%d",
name, ost->file_index, ost->index);
ctx = avfilter_graph_alloc_filter(graph, trim, filter_name);
if (!ctx)
return AVERROR(ENOMEM);
ret = av_opt_set_double(ctx, "duration", (double)of->recording_time / 1e6,
AV_OPT_SEARCH_CHILDREN);
if (ret < 0) {
av_log(ctx, AV_LOG_ERROR, "Error configuring the %s filter", name);
return ret;
}
ret = avfilter_init_str(ctx, NULL);
if (ret < 0)
return ret;
ret = avfilter_link(*last_filter, *pad_idx, ctx, 0);
if (ret < 0)
return ret;
*last_filter = ctx;
*pad_idx = 0;
return 0;
}
static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
{
char *pix_fmts;
@ -247,6 +293,11 @@ static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter,
pad_idx = 0;
}
ret = insert_trim(ost, &last_filter, &pad_idx);
if (ret < 0)
return ret;
if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
return ret;
@ -313,6 +364,10 @@ static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter,
pad_idx = 0;
}
ret = insert_trim(ost, &last_filter, &pad_idx);
if (ret < 0)
return ret;
if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
return ret;

View File

@ -43,4 +43,4 @@
0, 20500, 20500, 500, 1000, 0xf195eb44
0, 21000, 21000, 500, 1000, 0xa491f3ef
0, 21500, 21500, 500, 1000, 0x2c036e18
0, 22000, 22000, 500, 1000, 0x52d65e2a
0, 22000, 22000, 50, 100, 0x0bd81f05

View File

@ -140,5 +140,4 @@
1, 53835, 53835, 925, 1850, 0x5a303d1a
0, 296, 296, 1, 192000, 0x79b7417b
1, 54760, 54760, 537, 1074, 0x142ce7ba
1, 55297, 55297, 925, 1850, 0x7ff682f7
0, 300, 300, 1, 192000, 0x468d8db4
1, 55297, 55297, 258, 516, 0x98885b26

View File

@ -36,7 +36,7 @@
0, 30, 30, 1, 184320, 0x54975910
0, 31, 31, 1, 184320, 0xf4857db9
0, 32, 32, 1, 184320, 0x82d18161
1, 42552, 42552, 14184, 28368, 0x9101e519
1, 42552, 42552, 5835, 11670, 0x04aa0b1e
0, 33, 33, 1, 184320, 0x06d93bd0
0, 34, 34, 1, 184320, 0xa4304c00
0, 35, 35, 1, 184320, 0x5f77d9cd

View File

@ -29,4 +29,3 @@
0, 27, 27, 1, 57600, 0x4ec4a868
0, 28, 28, 1, 57600, 0x7db370a1
0, 29, 29, 1, 57600, 0x2b1e52f6
0, 30, 30, 1, 57600, 0x2141467c

View File

@ -1,3 +1,3 @@
379908755146d4ead062abe9c3b5c582 *./tests/data/lavf/lavf.aif
90166 ./tests/data/lavf/lavf.aif
./tests/data/lavf/lavf.aif CRC=0xf1ae5536
9d9e55431800bf6aea46a7d67509da4e *./tests/data/lavf/lavf.aif
88254 ./tests/data/lavf/lavf.aif
./tests/data/lavf/lavf.aif CRC=0x3a1da17e

View File

@ -1,3 +1,3 @@
8bce9c3758b0d38da2e0718b6ab57fb4 *./tests/data/lavf/lavf.al
45056 ./tests/data/lavf/lavf.al
./tests/data/lavf/lavf.al CRC=0x5e6d372b
652d96e474869ddb01403743deb35117 *./tests/data/lavf/lavf.al
44100 ./tests/data/lavf/lavf.al
./tests/data/lavf/lavf.al CRC=0xf9643112

View File

@ -1,3 +1,3 @@
93b1cbdb36d7306f7d31392c8cb9fed8 *./tests/data/lavf/lavf.asf
327385dd5f418faa6237089a40159b78 *./tests/data/lavf/lavf.asf
333375 ./tests/data/lavf/lavf.asf
./tests/data/lavf/lavf.asf CRC=0x51485213
./tests/data/lavf/lavf.asf CRC=0xf6340a10

View File

@ -1,3 +1,3 @@
dbd11f783219485cae32024e47c19dfb *./tests/data/lavf/lavf.au
90136 ./tests/data/lavf/lavf.au
./tests/data/lavf/lavf.au CRC=0xf1ae5536
b9396e3775ea009094e751e7128d614e *./tests/data/lavf/lavf.au
88224 ./tests/data/lavf/lavf.au
./tests/data/lavf/lavf.au CRC=0x3a1da17e

View File

@ -1,3 +1,3 @@
e6319b86a4422a8317124fc4cc693f8c *./tests/data/lavf/lavf.avi
e2e7b7ceaf038b259558f41df203ded9 *./tests/data/lavf/lavf.avi
330786 ./tests/data/lavf/lavf.avi
./tests/data/lavf/lavf.avi CRC=0xa79b84dd
./tests/data/lavf/lavf.avi CRC=0x4c963cda

View File

@ -1,3 +1,3 @@
71f4d64a6b3c71f43a4eff526f84841c *./tests/data/images/bmp/02.bmp
./tests/data/images/bmp/%02d.bmp CRC=0xe6c71946
./tests/data/images/bmp/%02d.bmp CRC=0x3447369b
304182 ./tests/data/images/bmp/02.bmp

View File

@ -1,3 +1,3 @@
808ea110635774252439722a48329d61 *./tests/data/images/dpx/02.dpx
./tests/data/images/dpx/%02d.dpx CRC=0x6da01946
./tests/data/images/dpx/%02d.dpx CRC=0x28c7369b
305792 ./tests/data/images/dpx/02.dpx

View File

@ -1,3 +1,3 @@
c5dcf5950031020864db57bbde0064df *./tests/data/lavf/lavf.ffm
f3f0c42283b75bc826f499f048085c27 *./tests/data/lavf/lavf.ffm
376832 ./tests/data/lavf/lavf.ffm
./tests/data/lavf/lavf.ffm CRC=0x38388ba1
./tests/data/lavf/lavf.ffm CRC=0xdd24439e

View File

@ -1,3 +1,3 @@
32e34e23f3740e27e5bcf1621a698aad *./tests/data/lavf/lavf.gxf
eaa16531d0b2f3e3ade2186cf33dbf86 *./tests/data/lavf/lavf.gxf
796392 ./tests/data/lavf/lavf.gxf
./tests/data/lavf/lavf.gxf CRC=0x4f52fc7f
./tests/data/lavf/lavf.gxf CRC=0xd04c769f

View File

@ -1,3 +1,3 @@
131878fee153a086d740543fbf2ab359 *./tests/data/images/jpg/02.jpg
./tests/data/images/jpg/%02d.jpg CRC=0x8b019f23
./tests/data/images/jpg/%02d.jpg CRC=0x9d770966
28406 ./tests/data/images/jpg/02.jpg

View File

@ -1,3 +1,3 @@
af61b3dcd6a9d2608c2368136c96b437 *./tests/data/lavf/lavf.mkv
7aa1846929e5fa4f5f2b1a0bc243218f *./tests/data/lavf/lavf.mkv
320262 ./tests/data/lavf/lavf.mkv
./tests/data/lavf/lavf.mkv CRC=0xd86284dd
./tests/data/lavf/lavf.mkv CRC=0x7d5d3cda

View File

@ -1,3 +1,3 @@
272b91d8fc31ed43b08246d182719751 *./tests/data/lavf/lavf.mmf
19625430b231dd130dbb0c13de1036fa *./tests/data/lavf/lavf.mmf
22609 ./tests/data/lavf/lavf.mmf
./tests/data/lavf/lavf.mmf CRC=0x03633476
./tests/data/lavf/lavf.mmf CRC=0x8dea1388

View File

@ -1,3 +1,3 @@
a5c982910b1a1547db68ffa35cc2a05a *./tests/data/lavf/lavf.mov
357741 ./tests/data/lavf/lavf.mov
./tests/data/lavf/lavf.mov CRC=0x2f6a9b26
8404cccff020ab07fbfe9c713bc98c33 *./tests/data/lavf/lavf.mov
356797 ./tests/data/lavf/lavf.mov
./tests/data/lavf/lavf.mov CRC=0xe3f4950d

View File

@ -1,3 +1,3 @@
253f28e374d51d264926c91e36043943 *./tests/data/lavf/lavf.mpg
7df31ba8a5909e3c88b1d1a3f93c4ec2 *./tests/data/lavf/lavf.mpg
372736 ./tests/data/lavf/lavf.mpg
./tests/data/lavf/lavf.mpg CRC=0x38388ba1
./tests/data/lavf/lavf.mpg CRC=0xdd24439e

View File

@ -1,3 +1,3 @@
e64027a96ad5907ee281deff3286da0a *./tests/data/lavf/lavf.ul
45056 ./tests/data/lavf/lavf.ul
./tests/data/lavf/lavf.ul CRC=0xe028b50a
ad492935e361f830f2f8302aa102701d *./tests/data/lavf/lavf.ul
44100 ./tests/data/lavf/lavf.ul
./tests/data/lavf/lavf.ul CRC=0x4515fa26

View File

@ -1,3 +1,3 @@
7e44a8ed5ff2fe5442f758d48fe1b496 *./tests/data/lavf/lavf.nut
8c9d5193a672ad0dee90f0712acc3a31 *./tests/data/lavf/lavf.nut
319680 ./tests/data/lavf/lavf.nut
./tests/data/lavf/lavf.nut CRC=0xa79b84dd
./tests/data/lavf/lavf.nut CRC=0x4c963cda

View File

@ -1,3 +1,3 @@
37147a98d9a484208389efa6a1f8796f *./tests/data/lavf/lavf.ogg
13966 ./tests/data/lavf/lavf.ogg
./tests/data/lavf/lavf.ogg CRC=0x37a143ea
8ca901bc8d24b80ebe79e387e454d1e9 *./tests/data/lavf/lavf.ogg
13476 ./tests/data/lavf/lavf.ogg
./tests/data/lavf/lavf.ogg CRC=0x3a1da17e

View File

@ -1,3 +1,3 @@
0dce5565222cf0f8b309467f279aecd2 *./tests/data/images/pam/02.pam
./tests/data/images/pam/%02d.pam CRC=0x6da01946
./tests/data/images/pam/%02d.pam CRC=0x28c7369b
304191 ./tests/data/images/pam/02.pam

View File

@ -1,3 +1,3 @@
2df1d747fba23d03b6ff9c91b8b465c9 *./tests/data/images/pcx/02.pcx
./tests/data/images/pcx/%02d.pcx CRC=0x6da01946
./tests/data/images/pcx/%02d.pcx CRC=0x28c7369b
364147 ./tests/data/images/pcx/02.pcx

View File

@ -1,3 +1,3 @@
388f5c51a678ca6a52cc006095c12f08 *./tests/data/images/pgm/02.pgm
./tests/data/images/pgm/%02d.pgm CRC=0x418d2963
./tests/data/images/pgm/%02d.pgm CRC=0xa6866b82
101391 ./tests/data/images/pgm/02.pgm

View File

@ -1,3 +1,3 @@
c162094e51dc1a3203de43e496086dfd *./tests/data/images/png/02.png
./tests/data/images/png/%02d.png CRC=0x6da01946
./tests/data/images/png/%02d.png CRC=0x28c7369b
248612 ./tests/data/images/png/02.png

View File

@ -1,3 +1,3 @@
16d5dadf0b362fc8ba3cb676c5dde985 *./tests/data/images/ppm/02.ppm
./tests/data/images/ppm/%02d.ppm CRC=0x6da01946
./tests/data/images/ppm/%02d.ppm CRC=0x28c7369b
304143 ./tests/data/images/ppm/02.ppm

View File

@ -1,2 +1,2 @@
c002d460bc77043ced69fd00f4ae7968 *./tests/data/lavf/lavf.rm
9eeb3b91c0a45f519fd7f2efea882cf4 *./tests/data/lavf/lavf.rm
346414 ./tests/data/lavf/lavf.rm

View File

@ -1,3 +1,3 @@
f41fd78f7df981802e7caeb23648b8c0 *./tests/data/lavf/lavf.rso
45064 ./tests/data/lavf/lavf.rso
./tests/data/lavf/lavf.rso CRC=0x74b2b546
443b72346065d6318ca18c8395aa1d87 *./tests/data/lavf/lavf.rso
44108 ./tests/data/lavf/lavf.rso
./tests/data/lavf/lavf.rso CRC=0x298fd284

View File

@ -1,3 +1,3 @@
7054acafd275e51cec28d4518e213081 *./tests/data/images/sgi/02.sgi
./tests/data/images/sgi/%02d.sgi CRC=0x6da01946
./tests/data/images/sgi/%02d.sgi CRC=0x28c7369b
308151 ./tests/data/images/sgi/02.sgi

View File

@ -1,3 +1,3 @@
e6f278256f145b69ed06f35b8d3585c1 *./tests/data/lavf/lavf.sox
180256 ./tests/data/lavf/lavf.sox
./tests/data/lavf/lavf.sox CRC=0xf1ae5536
683635d5cb1344e44fa96df90c3a993c *./tests/data/lavf/lavf.sox
176432 ./tests/data/lavf/lavf.sox
./tests/data/lavf/lavf.sox CRC=0x3a1da17e

View File

@ -1,3 +1,3 @@
07518bcb0841bc677ce6aea8464ea240 *./tests/data/images/sun/02.sun
./tests/data/images/sun/%02d.sun CRC=0xe6c71946
./tests/data/images/sun/%02d.sun CRC=0x3447369b
304123 ./tests/data/images/sun/02.sun

View File

@ -1,3 +1,3 @@
c0305c53e6d79d4ed9f35f04f671246c *./tests/data/images/tga/02.tga
./tests/data/images/tga/%02d.tga CRC=0xe6c71946
./tests/data/images/tga/%02d.tga CRC=0x3447369b
304172 ./tests/data/images/tga/02.tga

View File

@ -1,3 +1,3 @@
b3299346a8959553a437e486d8f3bf76 *./tests/data/images/tiff/02.tiff
./tests/data/images/tiff/%02d.tiff CRC=0x6da01946
./tests/data/images/tiff/%02d.tiff CRC=0x28c7369b
307131 ./tests/data/images/tiff/02.tiff

View File

@ -1,3 +1,3 @@
8572cdd0cd589d1bc899264d7f1ead81 *./tests/data/lavf/lavf.ts
647875edb0d1afb9fd0477cbfde3fe8b *./tests/data/lavf/lavf.ts
406456 ./tests/data/lavf/lavf.ts
./tests/data/lavf/lavf.ts CRC=0x0fdeb4df
./tests/data/lavf/lavf.ts CRC=0xb4ca6cdc

View File

@ -1,3 +1,3 @@
5c4ee01048e7a8a138a97e80cf7a1924 *./tests/data/lavf/lavf.voc
45261 ./tests/data/lavf/lavf.voc
./tests/data/lavf/lavf.voc CRC=0x74b2b546
ae01db5200e569371d4c27316575344c *./tests/data/lavf/lavf.voc
44305 ./tests/data/lavf/lavf.voc
./tests/data/lavf/lavf.voc CRC=0x298fd284

View File

@ -1,3 +1,3 @@
8ed10b311e49b4d4b18679b126492159 *./tests/data/lavf/lavf.s16.voc
180437 ./tests/data/lavf/lavf.s16.voc
./tests/data/lavf/lavf.s16.voc CRC=0x7bd585ff
e55a9c632cfeab90bcfb9ff29a71728c *./tests/data/lavf/lavf.s16.voc
176613 ./tests/data/lavf/lavf.s16.voc
./tests/data/lavf/lavf.s16.voc CRC=0xe61e3bd0

View File

@ -1,3 +1,3 @@
8854ea97f2d2172383941b001c69228b *./tests/data/lavf/lavf.wav
90158 ./tests/data/lavf/lavf.wav
./tests/data/lavf/lavf.wav CRC=0xf1ae5536
41410d9bbe0603740d1c17050746f475 *./tests/data/lavf/lavf.wav
88246 ./tests/data/lavf/lavf.wav
./tests/data/lavf/lavf.wav CRC=0x3a1da17e

View File

@ -1,3 +1,3 @@
50baa5560b7d1aa3188b19c1162bf7dc *./tests/data/images/xwd/02.xwd
./tests/data/images/xwd/%02d.xwd CRC=0x6da01946
./tests/data/images/xwd/%02d.xwd CRC=0x28c7369b
304239 ./tests/data/images/xwd/02.xwd

View File

@ -38,7 +38,7 @@ ret: 0 st: 0 flags:1 dts: 0.200816 pts: 0.200816 pos: 4428 size: 1024
ret: 0 st: 0 flags:0 ts:-0.904989
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size: 1024
ret: 0 st: 0 flags:1 ts: 1.989161
ret: 0 st: 0 flags:1 dts: 1.989161 pts: 1.989161 pos: 43861 size: 1024
ret: 0 st: 0 flags:1 dts: 1.989161 pts: 1.989161 pos: 43861 size: 239
ret: 0 st:-1 flags:0 ts: 0.883340
ret: 0 st: 0 flags:1 dts: 0.883356 pts: 0.883356 pos: 19478 size: 1024
ret: 0 st:-1 flags:1 ts:-0.222493

View File

@ -38,7 +38,7 @@ ret: 0 st: 0 flags:1 dts: 0.200816 pts: 0.200816 pos: 4428 size: 1024
ret: 0 st: 0 flags:0 ts:-0.904989
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size: 1024
ret: 0 st: 0 flags:1 ts: 1.989161
ret: 0 st: 0 flags:1 dts: 1.989161 pts: 1.989161 pos: 43861 size: 1024
ret: 0 st: 0 flags:1 dts: 1.989161 pts: 1.989161 pos: 43861 size: 239
ret: 0 st:-1 flags:0 ts: 0.883340
ret: 0 st: 0 flags:1 dts: 0.883356 pts: 0.883356 pos: 19478 size: 1024
ret: 0 st:-1 flags:1 ts:-0.222493