Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 从较长视频的选定秒数生成新视频_Python 3.x_Video_Ffmpeg - Fatal编程技术网

Python 3.x 从较长视频的选定秒数生成新视频

Python 3.x 从较长视频的选定秒数生成新视频,python-3.x,video,ffmpeg,Python 3.x,Video,Ffmpeg,我尝试生成10分钟原始videofile.mp4的较短版本,其中仅包含原始文件的四个10秒子片段(即从10秒到20秒;从197秒到207秒;从393秒到403秒;从570秒到580秒)。到目前为止,我只能复制视频和音频生成4个新文件: ffmpeg -i videofile.mp4 -vcodec copy -acodec copy -ss 10 -to 20 videofile1.mp4 -vcodec copy -acodec copy -ss 197 -to 207 videofile2.

我尝试生成10分钟原始videofile.mp4的较短版本,其中仅包含原始文件的四个10秒子片段(即从10秒到20秒;从197秒到207秒;从393秒到403秒;从570秒到580秒)。到目前为止,我只能复制视频和音频生成4个新文件:

ffmpeg -i videofile.mp4 -vcodec copy -acodec copy -ss 10 -to 20 videofile1.mp4 -vcodec copy -acodec copy -ss 197 -to 207 videofile2.mp4 -vcodec copy -acodec copy -ss 393 -to 403 videofile3.mp4 -vcodec copy -acodec copy -ss 570 -to 580 videofile4.mp4
但是,我在连接这4个子唇以生成所需的40秒out\u videofile.mp4时遇到了很大的困难。我在ffmpeg中找到了使用“select”命令的替代方法,它使我省去了“失败”的连接过程。到目前为止,我已经:

ffmpeg -i videofile.mp4 -vf "select='between(t,10,20)+between(t,197,207)+between(t,393,403)+between(t,570,580)',setpts=N/FRAME_RATE/TB" -af "aselect='between(t,10,20)+between(t,197,207)+between(t,393,403)+between(t,570,580)" out_videofile.mp4
我想这最后一段代码应该会给出我想要的40s out\u videofile.mp4。但是,它给了我一个“SyntaxError:invalid syntax”。知道我哪里出错了吗


无论如何,谢谢你抽出时间

您缺少一个结束引号,但也缺少一个用于平滑音频时间戳的过滤器

使用


谢谢@Gyan。看来也不行。相同的“语法错误:无效语法”。事实上,我使用Python和崇高的文本,并调用ffmpeg,我做
import subprocess//command='ffmpeg-I videofile.mp4-vf“select='between(t,10,20)+between(t,197,207)+between(t,393,403)+between(t,570,580)”,setpts=N/FRAME\u RATE/TB“-af”aselect='between(t,10,20)+between(t,197,207)+between(t,393,403)(t,570580)”,asetpts=N/SR/TB“out\u videofile.mp4'//subprocess.call(命令,shell=True)
。我想这不应该是个问题,对吧?是的。不熟悉python,但命令中的单引号可能需要转义。谢谢@Gyan,我在终端上尝试了它并成功了!虽然我在输出视频上失去了分辨率……我想没有办法“解决”这…如果编码器是x264,则需要设置质量级别,如
-crf 20
ffmpeg -i videofile.mp4 -vf "select='between(t,10,20)+between(t,197,207)+between(t,393,403)+between(t,570,580)',setpts=N/FRAME_RATE/TB" -af "aselect='between(t,10,20)+between(t,197,207)+between(t,393,403)+between(t,570,580)',asetpts=N/SR/TB" out_videofile.mp4