在Google Colab上保存文件

时间:2019-12-03 23:19:00

标签: python google-drive-api google-colaboratory moviepy

我正在处理使用moviepy在Google colab上的Google驱动器中存储的视频。我想将修剪过的视频保存在gogle驱动器上的当前工作目录中,但是无法这样做。下面是我正在使用的代码(IIUC目标名称是我指定要创建的新文件的名称的地方):

ffmpeg_extract_subclip("A1203.mp4", start_time, end_time, targetname='test.mp4')
files.download('test.mp4')

这是我的错误消息:

[MoviePy] Running:
>>> /usr/bin/ffmpeg -y -i D1203H.mp4 -ss 0.00 -t 300.00 -vcodec copy -acodec copy test.mp4
[MoviePy] This command returned an error !
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-4-8d9207533dd4> in <module>()
      2 end_time = 300
      3 
----> 4 ffmpeg_extract_subclip("D1203H.mp4", start_time, end_time, targetname='test.mp4')
      5 files.download('test.mp4')

1 frames
/usr/local/lib/python3.6/dist-packages/moviepy/tools.py in subprocess_call(cmd, verbose, errorprint)
     47     if proc.returncode:
     48         verbose_print(errorprint, "\n[MoviePy] This command returned an error !")
---> 49         raise IOError(err.decode('utf8'))
     50     else:
     51         verbose_print(verbose, "\n... command successful.\n")

OSError: ffmpeg version 3.4.6-0ubuntu0.18.04.1 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
  configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'D1203H.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : HandBrake 0.10.0 2014112200
  Duration: 01:57:36.82, start: 0.000000, bitrate: 1975 kb/s
    Stream #0:0(und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 720x480 [SAR 8:9 DAR 4:3], 1803 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 30k tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 166 kb/s (default)
    Metadata:
      handler_name    : Stereo
test.mp4: Read-only file system

1 个答案:

答案 0 :(得分:1)

您提供的代码和错误消息中的代码不同。在后者中指出:

ffmpeg_extract_subclip("D1203H.mp4", start_time, end_time, targetname=files.download('test.mp4'))

这也是执行失败的原因。您尝试通过files.download('test.mp4')从当前目录下载test.mp4,但由于该目录尚不存在,因此失败。因此,您必须先调用不带files.download()的命令,然后再进行下载

ffmpeg_extract_subclip("D1203H.mp4", start_time, end_time, targetname='test.mp4')
files.download('test.mp4')