X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavdevice%2Flavfi.c;h=0a6eb913ddc002a07e3ef290fb4c7b03c91da9dd;hb=e6ad9437346a78535df78efda3710e890e2586d6;hp=de3731a086594b62432259b2869eac59f3b22558;hpb=0bb57f8bf029427059be21a562527dcfa0e264c9;p=ffmpeg diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c index de3731a0865..0a6eb913ddc 100644 --- a/libavdevice/lavfi.c +++ b/libavdevice/lavfi.c @@ -32,6 +32,7 @@ #include "libavutil/opt.h" #include "libavutil/parseutils.h" #include "libavutil/pixdesc.h" +#include "libavutil/audioconvert.h" #include "libavfilter/avfilter.h" #include "libavfilter/avfiltergraph.h" #include "libavfilter/buffersink.h" @@ -41,6 +42,7 @@ typedef struct { AVClass *class; ///< class for private options char *graph_str; + char *dump_graph; AVFilterGraph *graph; AVFilterContext **sinks; int *sink_stream_map; @@ -77,8 +79,7 @@ av_cold static int lavfi_read_close(AVFormatContext *avctx) return 0; } -av_cold static int lavfi_read_header(AVFormatContext *avctx, - AVFormatParameters *ap) +av_cold static int lavfi_read_header(AVFormatContext *avctx) { LavfiContext *lavfi = avctx->priv_data; AVFilterInOut *input_links = NULL, *output_links = NULL, *inout; @@ -205,7 +206,11 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx, if (ret < 0) goto end; } else if (type == AVMEDIA_TYPE_AUDIO) { - enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_S16, -1 }; + enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_U8, + AV_SAMPLE_FMT_S16, + AV_SAMPLE_FMT_S32, + AV_SAMPLE_FMT_FLT, + AV_SAMPLE_FMT_DBL, -1 }; const int packing_fmts[] = { AVFILTER_PACKED, -1 }; const int64_t *chlayouts = avfilter_all_channel_layouts; AVABufferSinkParams *abuffersink_params = av_abuffersink_params_alloc(); @@ -230,6 +235,13 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx, if ((ret = avfilter_graph_config(lavfi->graph, avctx)) < 0) FAIL(ret); + if (lavfi->dump_graph) { + char *dump = avfilter_graph_dump(lavfi->graph, lavfi->dump_graph); + fputs(dump, stderr); + fflush(stderr); + av_free(dump); + } + /* fill each stream with the information in the corresponding sink */ for (i = 0; i < avctx->nb_streams; i++) { AVFilterLink *link = lavfi->sinks[lavfi->stream_sink_map[i]]->inputs[0]; @@ -245,12 +257,16 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx, st ->sample_aspect_ratio = st->codec->sample_aspect_ratio = link->sample_aspect_ratio; } else if (link->type == AVMEDIA_TYPE_AUDIO) { - st->codec->codec_id = CODEC_ID_PCM_S16LE; + st->codec->codec_id = av_get_pcm_codec(link->format, -1); st->codec->channels = av_get_channel_layout_nb_channels(link->channel_layout); st->codec->sample_fmt = link->format; st->codec->sample_rate = link->sample_rate; st->codec->time_base = link->time_base; st->codec->channel_layout = link->channel_layout; + if (st->codec->codec_id == CODEC_ID_NONE) + av_log(avctx, AV_LOG_ERROR, + "Could not find PCM codec for sample format %s.\n", + av_get_sample_fmt_name(link->format)); } } @@ -329,6 +345,7 @@ static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt) static const AVOption options[] = { { "graph", "Libavfilter graph", OFFSET(graph_str), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC }, + { "dumpgraph", "Dump graph to stderr", OFFSET(dump_graph), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, { NULL }, };