Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Speed change command fails when audio stream is not present in video - ffmpeg

I am trying to change speed of the video that does not contain audio stream via below command

String[]{"ffmpeg", "-y", "-i", orginalFile, "-threads", "5", "-preset", "ultrafast", "-strict", "experimental", "-filter_complex", "[0:v]setpts=0.50*PTS[v];[0:a]atempo=2.0[a]", "-map", "[v]", "-map", "[a]", "-b", "2097k", "-ab", "48000", "-ac", "2", "-ar", "22050", "-vcodec", "mpeg4", destinationFile};

Command fails stating that video does not have audio stream. So, do I need to check whether audio stream is present in the video or is there something I can do in this scenario?

like image 962
Lalit Sharma Avatar asked Jul 06 '16 07:07

Lalit Sharma


People also ask

How do I use FFmpeg in the terminal on a Mac?

In order to use FFmpeg in the ‘Terminal’ of an Apple macOS computer you have to install it. Installation instructions can be found in my blog post ‘ Fixing corrupted AVI indexes ‘.

How to harmonize audio streams in video files on Mac?

Harmonizing the order of audio streams in your video files can be done by using the free open source tool FFmpeg in the ‘Terminal’. In order to use FFmpeg in the ‘Terminal’ of an Apple macOS computer you have to install it.

What is a forced audio stream and how does it work?

A forced audio stream will override the settings in your video player. If you defined English as your preferred audio language in your video player, with this example file the player would play the German language nevertheless.


3 Answers

You need to check the video before running the command (using ffmpeg -i ) You will get the information in the vk.log. Parse it, and see if you have audio. Then run the correct command.

like image 119
Eli Avatar answered Nov 08 '22 13:11

Eli


Option -map a only accept video with audio stream, There are some video have not audio. you need use -map 0. Solution for two case is you use ?:

 -map [a?]

The ? teels ffmpeg to only map the stream if it exists.

like image 45
mdtuyen Avatar answered Nov 08 '22 13:11

mdtuyen


If you use stream-specific filterchains, you use should be able to process all files - with or without audio.

Use

String[]{"ffmpeg", "-y", "-i", originalFile, "-threads", "5",
         "-map", "0:v", "-map", "0:a?",
         "-vf setpts=0.50*PTS", "-vcodec", "mpeg4", "-preset", "ultrafast", "-b:v", "2097k",
         "-af atempo=2.0", "-b:a", "48000", "-ac", "2", "-ar", "22050",
         "-strict", "experimental", destinationFile}
like image 43
Gyan Avatar answered Nov 08 '22 14:11

Gyan