简体   繁体   English

当视频中没有音频流时,速度更改命令会失败 - ffmpeg

[英]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? 那么,我是否需要检查视频中是否存在音频流,或者在这种情况下我能做些什么?

You need to check the video before running the command (using ffmpeg -i ) You will get the information in the vk.log. 您需要在运行命令之前检查视频(使用ffmpeg -i)您将获得vk.log中的信息。 Parse it, and see if you have audio. 解析它,看看你是否有音频。 Then run the correct command. 然后运行正确的命令。

Option -map a only accept video with audio stream, There are some video have not audio. 选项 - -map a只接受带有音频流的视频,有些视频没有音频。 you need use -map 0 . 你需要使用-map 0 Solution for two case is you use ? 两个案例的解决方案是你使用? :

 -map [a?]

The ? ? teels ffmpeg to only map the stream if it exists. teels ffmpeg仅映射流(如果存在)。

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}

One solution which you can try is to first convert video using this command: 您可以尝试的一种解决方案是首先使用此命令转换video

 String[]{"-ss", lastTime, "-i", selectedVideoPath, "-t", now,  "-filter:v", "setpts=0.5*PTS","-strict", "-2", videoPath};

Then convert audio and check if it executes try code or catch on the basis of result.If audio is successfully executed then merge audio and video else save finalized video without audio . 然后转换audio并检查它是否执行try code or catch基于结果try code or catch 。如果audio成功执行,则merge audiovideo否则保存没有audio最终video

it might not be the best solution but it should work. 它可能不是最好的解决方案,但它应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM