如果系统argv包含“&”ch

2024-09-20 22:52:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个Python脚本,它使用youtube-dl下载视频,然后使用ffmpeg从中提取帧。代码如下:

def DownloadVideo():
    output_file = "/Users/francesco/Desktop/SOURCE/%(title)s-%(id)s.%(ext)s"
    check_call(["youtube-dl","--output", output_file, "--restrict-filenames", "-f", "best", sys.argv[1]])

def ConvertVideo(video):
    DEST = "/Users/francesco/Desktop/OUTPUT"
    SOURCE = "/Users/francesco/Desktop/SOURCE"
    ffmpeg_path = "/Users/francesco/Desktop/ffmpeg/ffmpeg"
    video_path = SOURCE + "/" + video
    dest_path = DEST + "/" + os.path.splitext(video)[0] + "-%d.png"
    check_call([ffmpeg_path, "-v", "0", "-i", video_path, "-f", "image2", dest_path])

def Main():
    DownloadVideo()
    for video in os.listdir("/Users/francesco/Desktop/SOURCE"):
       ConvertVideo(video)

我运行命令python myscript.py myvideolink,下载过程中一切正常,但ConvertVideo没有启动,只是冻结了几秒钟,然后程序退出。你知道吗

如果我尝试跳过DownloadVideo()(视频已经下载到文件夹中)运行相同的命令,它也不起作用,但是如果我在没有argv[1]的情况下使用python myscript.py,ffmpeg进程就起作用了!为什么会这样?你知道吗

更新:我尝试删除ffmpeg中的-v 0选项,以查看实际发生的情况,ffmpeg进程启动,但冻结如下:

ffmpeg version 2.6.2 Copyright (c) 2000-2015 the FFmpeg developers
  built with llvm-gcc 4.2.1 (LLVM build 2336.11.00)
  configuration: --prefix=/Volumes/Ramdisk/sw --enable-gpl --enable-pthreads --enable-version3 --enable-libspeex --enable-libvpx --disable-decoder=libvpx --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-avfilter --enable-libopencore_amrwb --enable-libopencore_amrnb --enable-filters --enable-libgsm --enable-libvidstab --enable-libx265 --disable-doc --arch=x86_64 --enable-runtime-cpudetect
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100

更新2:结果表明,只有当参数(链接)包含字符“&;时,才会发生这种情况。有人知道为什么这是ffmpeg的问题吗?他既没有使用arg变量。。。你知道吗


Tags: pathsourceoutputyoutubeenabledefvideo情况
1条回答
网友
1楼 · 发布于 2024-09-20 22:52:04

我猜您正在指定一个已经存在的输出位置,FFmpeg会询问您是否要覆盖该文件,等待stdin上的“y”(或其他任何东西,这意味着否)。要防止它这样做,请使用“-y”选项,这样可以防止它询问该问题并强制覆盖输出文件。你知道吗

相关问题 更多 >

    热门问题