History

lavfi: add amovie source - audio movie source

Stefano Sabatini committed 15 years ago

Commit 24ddfb21 parent 1d6eca27 files · +196 −2Browse files

Unified · Split

7 files
  1. Changelog +1 −0
  2. configure +1 −0
  3. doc/filters.texi +32 −0
  4. libavfilter/Makefile +2 −0
  5. libavfilter/allfilters.c +1 −0
  6. libavfilter/avfilter.h +2 −2
  7. libavfilter/src_movie.c +157 −0
Changelog+1−0
@@ -46,6 +46,7 @@ easier to use. The changes are: · 45 unmodified lines
46- LOAS demuxer46- LOAS demuxer
47- ashowinfo filter added47- ashowinfo filter added
48- Windows Media Image decoder48- Windows Media Image decoder
49- amovie source added
49 50
50 51
51version 0.8:52version 0.8:
configure+1−0
@@ -1505,6 +1505,7 @@ udp_protocol_deps="network" · 1504 unmodified lines
1505# filters1505# filters
1506abuffer_filter_deps="strtok_r"1506abuffer_filter_deps="strtok_r"
1507aformat_filter_deps="strtok_r"1507aformat_filter_deps="strtok_r"
1508amovie_filter_deps="avcodec avformat"
1508blackframe_filter_deps="gpl"1509blackframe_filter_deps="gpl"
1509boxblur_filter_deps="gpl"1510boxblur_filter_deps="gpl"
1510cropdetect_filter_deps="gpl"1511cropdetect_filter_deps="gpl"
doc/filters.texi+32−0
@@ -239,6 +239,38 @@ equivalent to: · 238 unmodified lines
239abuffer=44100:1:3:1239abuffer=44100:1:3:1
240@end example240@end example
241 241
242@section amovie
243
244Read an audio stream from a movie container.
245
246It accepts the syntax: @var{movie_name}[:@var{options}] where
247@var{movie_name} is the name of the resource to read (not necessarily
248a file but also a device or a stream accessed through some protocol),
249and @var{options} is an optional sequence of @var{key}=@var{value}
250pairs, separated by ":".
251
252The description of the accepted options follows.
253
254@table @option
255
256@item format_name, f
257Specify the format assumed for the movie to read, and can be either
258the name of a container or an input device. If not specified the
259format is guessed from @var{movie_name} or by probing.
260
261@item seek_point, sp
262Specify the seek point in seconds, the frames will be output
263starting from this seek point, the parameter is evaluated with
264@code{av_strtod} so the numerical value may be suffixed by an IS
265postfix. Default value is "0".
266
267@item stream_index, si
268Specify the index of the audio stream to read. If the value is -1,
269the best suited audio stream will be automatically selected. Default
270value is "-1".
271
272@end table
273
242@section anullsrc274@section anullsrc
243 275
244Null audio source, never return audio frames. It is mainly useful as a276Null audio source, never return audio frames. It is mainly useful as a
libavfilter/Makefile+2−0
@@ -2,6 +2,7 @@ include $(SUBDIR)../config.mak · 1 unmodified line
2 2
3NAME = avfilter3NAME = avfilter
4FFLIBS = avutil4FFLIBS = avutil
5FFLIBS-$(CONFIG_AMOVIE_FILTER) += avformat avcodec
5FFLIBS-$(CONFIG_ARESAMPLE_FILTER) += avcodec6FFLIBS-$(CONFIG_ARESAMPLE_FILTER) += avcodec
6FFLIBS-$(CONFIG_MOVIE_FILTER) += avformat avcodec7FFLIBS-$(CONFIG_MOVIE_FILTER) += avformat avcodec
7FFLIBS-$(CONFIG_SCALE_FILTER) += swscale8FFLIBS-$(CONFIG_SCALE_FILTER) += swscale
@@ -25,6 +26,7 @@ OBJS-$(CONFIG_ARESAMPLE_FILTER) += af_aresample.o · 17 unmodified lines
25OBJS-$(CONFIG_ASHOWINFO_FILTER) += af_ashowinfo.o26OBJS-$(CONFIG_ASHOWINFO_FILTER) += af_ashowinfo.o
26 27
27OBJS-$(CONFIG_ABUFFER_FILTER) += asrc_abuffer.o28OBJS-$(CONFIG_ABUFFER_FILTER) += asrc_abuffer.o
29OBJS-$(CONFIG_AMOVIE_FILTER) += src_movie.o
28OBJS-$(CONFIG_ANULLSRC_FILTER) += asrc_anullsrc.o30OBJS-$(CONFIG_ANULLSRC_FILTER) += asrc_anullsrc.o
29 31
30OBJS-$(CONFIG_ABUFFERSINK_FILTER) += asink_abuffer.o32OBJS-$(CONFIG_ABUFFERSINK_FILTER) += asink_abuffer.o
libavfilter/allfilters.c+1−0
@@ -40,6 +40,7 @@ void avfilter_register_all(void) · 39 unmodified lines
40 REGISTER_FILTER (ASHOWINFO, ashowinfo, af);40 REGISTER_FILTER (ASHOWINFO, ashowinfo, af);
41 41
42 REGISTER_FILTER (ABUFFER, abuffer, asrc);42 REGISTER_FILTER (ABUFFER, abuffer, asrc);
43 REGISTER_FILTER (AMOVIE, amovie, asrc);
43 REGISTER_FILTER (ANULLSRC, anullsrc, asrc);44 REGISTER_FILTER (ANULLSRC, anullsrc, asrc);
44 45
45 REGISTER_FILTER (ABUFFERSINK, abuffersink, asink);46 REGISTER_FILTER (ABUFFERSINK, abuffersink, asink);
libavfilter/avfilter.h+2−2
@@ -29,8 +29,8 @@ · 28 unmodified lines
29#include "libavutil/rational.h"29#include "libavutil/rational.h"
30 30
31#define LIBAVFILTER_VERSION_MAJOR 231#define LIBAVFILTER_VERSION_MAJOR 2
32#define LIBAVFILTER_VERSION_MINOR 3432#define LIBAVFILTER_VERSION_MINOR 35
33#define LIBAVFILTER_VERSION_MICRO 233#define LIBAVFILTER_VERSION_MICRO 0
34 34
35#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \35#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
36 LIBAVFILTER_VERSION_MINOR, \36 LIBAVFILTER_VERSION_MINOR, \
libavfilter/src_movie.c+157−0
@@ -55,6 +55,13 @@ typedef struct { · 54 unmodified lines
55 /* video-only fields */55 /* video-only fields */
56 int w, h;56 int w, h;
57 AVFilterBufferRef *picref;57 AVFilterBufferRef *picref;
58
59 /* audio-only fields */
60 void *samples_buf;
61 int samples_buf_size;
62 int bps; ///< bytes per sample
63 AVPacket pkt, pkt0;
64 AVFilterBufferRef *samplesref;
58} MovieContext;65} MovieContext;
59 66
60#define OFFSET(x) offsetof(MovieContext, x)67#define OFFSET(x) offsetof(MovieContext, x)
@@ -185,8 +192,13 @@ static av_cold void movie_common_uninit(AVFilterContext *ctx) · 124 unmodified lines
185 192
186 avfilter_unref_buffer(movie->picref);193 avfilter_unref_buffer(movie->picref);
187 av_freep(&movie->frame);194 av_freep(&movie->frame);
195
196 avfilter_unref_buffer(movie->samplesref);
197 av_freep(&movie->samples_buf);
188}198}
189 199
200#if CONFIG_MOVIE_FILTER
201
190static av_cold int movie_init(AVFilterContext *ctx, const char *args, void *opaque)202static av_cold int movie_init(AVFilterContext *ctx, const char *args, void *opaque)
191{203{
192 MovieContext *movie = ctx->priv;204 MovieContext *movie = ctx->priv;
@@ -317,3 +329,148 @@ AVFilter avfilter_vsrc_movie = { · 124 unmodified lines
317 .config_props = movie_config_output_props, },329 .config_props = movie_config_output_props, },
318 { .name = NULL}},330 { .name = NULL}},
319};331};
332
333#endif /* CONFIG_MOVIE_FILTER */
334
335#if CONFIG_AMOVIE_FILTER
336
337static av_cold int amovie_init(AVFilterContext *ctx, const char *args, void *opaque)
338{
339 MovieContext *movie = ctx->priv;
340 int ret;
341
342 if ((ret = movie_common_init(ctx, args, opaque, AVMEDIA_TYPE_AUDIO)) < 0)
343 return ret;
344
345 movie->bps = av_get_bytes_per_sample(movie->codec_ctx->sample_fmt);
346 return 0;
347}
348
349static int amovie_query_formats(AVFilterContext *ctx)
350{
351 MovieContext *movie = ctx->priv;
352 AVCodecContext *c = movie->codec_ctx;
353
354 enum AVSampleFormat sample_fmts[] = { c->sample_fmt, -1 };
355 int packing_fmts[] = { AVFILTER_PACKED, -1 };
356 int64_t chlayouts[] = { c->channel_layout, -1 };
357
358 avfilter_set_common_sample_formats (ctx, avfilter_make_format_list(sample_fmts));
359 avfilter_set_common_packing_formats(ctx, avfilter_make_format_list(packing_fmts));
360 avfilter_set_common_channel_layouts(ctx, avfilter_make_format64_list(chlayouts));
361
362 return 0;
363}
364
365static int amovie_config_output_props(AVFilterLink *outlink)
366{
367 MovieContext *movie = outlink->src->priv;
368 AVCodecContext *c = movie->codec_ctx;
369
370 outlink->sample_rate = c->sample_rate;
371 outlink->time_base = movie->format_ctx->streams[movie->stream_index]->time_base;
372
373 return 0;
374}
375
376static int amovie_get_samples(AVFilterLink *outlink)
377{
378 MovieContext *movie = outlink->src->priv;
379 AVPacket pkt;
380 int ret, samples_size, decoded_data_size;
381
382 if (!movie->pkt.size && movie->is_done == 1)
383 return AVERROR_EOF;
384
385 /* check for another frame, in case the previous one was completely consumed */
386 if (!movie->pkt.size) {
387 while ((ret = av_read_frame(movie->format_ctx, &pkt)) >= 0) {
388 // Is this a packet from the selected stream?
389 if (pkt.stream_index != movie->stream_index) {
390 av_free_packet(&pkt);
391 continue;
392 } else {
393 movie->pkt0 = movie->pkt = pkt;
394 break;
395 }
396 }
397
398 if (ret == AVERROR_EOF) {
399 movie->is_done = 1;
400 return ret;
401 }
402 }
403
404 /* reallocate the buffer for the decoded samples, if necessary */
405 samples_size =
406 FFMAX(movie->pkt.size*sizeof(movie->bps), AVCODEC_MAX_AUDIO_FRAME_SIZE);
407 if (samples_size > movie->samples_buf_size) {
408 movie->samples_buf = av_fast_realloc(movie->samples_buf,
409 &movie->samples_buf_size, samples_size);
410 if (!movie->samples_buf)
411 return AVERROR(ENOMEM);
412 }
413 decoded_data_size = movie->samples_buf_size;
414
415 /* decode and update the movie pkt */
416 ret = avcodec_decode_audio3(movie->codec_ctx, movie->samples_buf,
417 &decoded_data_size, &movie->pkt);
418 if (ret < 0)
419 return ret;
420 movie->pkt.data += ret;
421 movie->pkt.size -= ret;
422
423 /* wrap the decoded data in a samplesref */
424 if (decoded_data_size > 0) {
425 int nb_samples = decoded_data_size / movie->bps / movie->codec_ctx->channels;
426 movie->samplesref =
427 avfilter_get_audio_buffer(outlink, AV_PERM_WRITE,
428 movie->codec_ctx->sample_fmt, nb_samples,
429 movie->codec_ctx->channel_layout, 0);
430 memcpy(movie->samplesref->data[0], movie->samples_buf, decoded_data_size);
431 movie->samplesref->pts = movie->pkt.pts;
432 movie->samplesref->pos = movie->pkt.pos;
433 movie->samplesref->audio->sample_rate = movie->codec_ctx->sample_rate;
434 }
435
436 // We got it. Free the packet since we are returning
437 if (movie->pkt.size <= 0)
438 av_free_packet(&movie->pkt0);
439
440 return 0;
441}
442
443static int amovie_request_frame(AVFilterLink *outlink)
444{
445 MovieContext *movie = outlink->src->priv;
446 int ret;
447
448 if (movie->is_done)
449 return AVERROR_EOF;
450 if ((ret = amovie_get_samples(outlink)) < 0)
451 return ret;
452
453 avfilter_filter_samples(outlink, avfilter_ref_buffer(movie->samplesref, ~0));
454 avfilter_unref_buffer(movie->samplesref);
455 movie->samplesref = NULL;
456
457 return 0;
458}
459
460AVFilter avfilter_asrc_amovie = {
461 .name = "amovie",
462 .description = NULL_IF_CONFIG_SMALL("Read audio from a movie source."),
463 .priv_size = sizeof(MovieContext),
464 .init = amovie_init,
465 .uninit = movie_common_uninit,
466 .query_formats = amovie_query_formats,
467
468 .inputs = (AVFilterPad[]) {{ .name = NULL }},
469 .outputs = (AVFilterPad[]) {{ .name = "default",
470 .type = AVMEDIA_TYPE_AUDIO,
471 .request_frame = amovie_request_frame,
472 .config_props = amovie_config_output_props, },
473 { .name = NULL}},
474};
475
476#endif /* CONFIG_AMOVIE_FILTER */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t