3

I am creating a video output using some overlays and scale layers through filter_complex of ffmpeg. I am using ffmpeg v3.3.2

I am using following command for videos with audio:

# avideo -> aoutput : 50% Faster
ffmpeg3 \
    -i avideo.wmv \
    -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" \
    -map "[v]" \
    -map "[a]" \
    aoutput.wmv

I am using following command for videos without audio:

# video -> output : 50% Faster
ffmpeg3 \
    -i video.wmv \
    -f lavfi -t 0.1 -i anullsrc \
    -filter_complex "[0:v]setpts=0.5*PTS[v]" \
    -map "[v]" \
    output.wmv

This works fine. But, I don't know if a video file has any audio streams in it or not. I need to make this command work for both of these scenarios.

I am trying to use following command for this:

# unknown(avideo, video) -> uoutput : 50% Faster
ffmpeg3 \
    -i video.wmv \
    -f lavfi -t 0.1 -i anullsrc \
    -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" \
    -map "[v]" \
    -map "[a]" \
    uoutput.wmv

But, this fails because input video doesn't have any audio stream. Exact error message is

Stream specifier ':a' in filtergraph description [0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a] matches no streams.

This question is most similar to my question: FFmpeg map optional (audio) stream, except that they aren't using filter_complex to execute this optional scenario. So, conditional mapping option wouldn't work for me.

How can I tell ffmpeg to use audio stream, in filter_complex, if there's any audio, otherwise ignore audio.

  • I want to do this in a single command.
  • I want to use ffmpeg alone (no ffprobe: size issues).

But, if you have any good options, please share them.

Edit:

I have updated my command with "-af atempo=2.0" and this seems to fix my issue. I do it like this.

ffmpeg3 \
    -i video.wmv \
    -af atempo=2.0 \
    -filter_complex "[0:v]setpts=0.5*PTS" \
    uoutput.wmv

But, I am still open to more options. Above fix seems wrong. While this works for all formats, but fails for WMV of 30sec with a bug https://trac.ffmpeg.org/ticket/6375

1 Answer 1

2

There are two possible hacks for this.

1) If you don't combine processed streams inside the filtergraph, then just use simple filterchains.

ffmpeg \
-i avideo.wmv \
-vf "setpts=0.5*PTS" \
-af "atempo=2.0" \
aoutput.wmv

The audio chain will only be parsed if an an audio output stream is present.

2) Add a dummy audio input and leave out the input label for the audio filtering. ffmpeg will pick the first available audio stream.

ffmpeg \
    -i video.wmv \
    -f lavfi -t 0.1 -i anullsrc \
    -filter_complex "[0:v]setpts=0.5*PTS[v];atempo=2.0[a]" \
    -map "[v]" \
    -map "[a]" \
    uoutput.wmv

I recommend you upgrade to ffmpeg 4.0 or later. There were some filtering bugs in 3.x series, since fixed.

1
  • i have 2 videos too be concat using ffmpeg in android. we dont know user will select mute video or video with sound. how can we concat e those videos? if videos has audio then its working fine but if one of them dont have audio stream then ffmpeg throws and error no matches stream Apr 1, 2021 at 6:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .