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