0

I have a string stored in a variable. The string represents the path to a video file. I want to run this command in jupyter-lab:

path = 'video.mp4'
meta = !ffmpeg -i path

This results in file not found.

If I directly enter the path, it works, like this:

meta = !ffmpeg -i video.mp4
print(meta)
['ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers',
 '  built with Apple clang version 11.0.3 (clang-1103.0.32.62)',
 '  configuration: --prefix=/opt/local --enable-swscale --enable-avfilter --enable-avresample --enable-libmp3lame --enable-libvorbis --enable-libopus --enable-librsvg --enable-libtheora --enable-libopenjpeg --enable-libmodplug --enable-libvpx --enable-libsoxr --enable-libspeex --enable-libass --enable-libbluray --enable-lzma --enable-gnutls --enable-fontconfig --enable-libfreetype --enable-libfribidi --disable-libjack --disable-libopencore-amrnb --disable-libopencore-amrwb --disable-libxcb --disable-libxcb-shm --disable-libxcb-xfixes --disable-indev=jack --enable-opencl --disable-outdev=xv --enable-audiotoolbox --enable-videotoolbox --enable-sdl2 --disable-securetransport --mandir=/opt/local/share/man --enable-shared --enable-pthreads --cc=/usr/bin/clang --enable-libdav1d --arch=x86_64 --enable-x86asm --enable-libx265 --enable-gpl --enable-postproc --enable-libx264 --enable-libxvid',
 '  libavutil      56. 51.100 / 56. 51.100',
 '  libavcodec     58. 91.100 / 58. 91.100',
 '  libavformat    58. 45.100 / 58. 45.100',
 '  libavdevice    58. 10.100 / 58. 10.100',
 '  libavfilter     7. 85.100 /  7. 85.100',
 '  libavresample   4.  0.  0 /  4.  0.  0',
 '  libswscale      5.  7.100 /  5.  7.100',
 '  libswresample   3.  7.100 /  3.  7.100',
 '  libpostproc    55.  7.100 / 55.  7.100',
 "Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':",
 '  Metadata:',
 '    major_brand     : isom',
 '    minor_version   : 512',
 '    compatible_brands: isomiso2avc1mp41',
 '    encoder         : Lavf58.45.100',
 '  Duration: 00:00:17.34, start: 0.000000, bitrate: 479106 kb/s',
 '    Stream #0:0(eng): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv420p, 2160x3840 [SAR 1:1 DAR 9:16], 479126 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)',
 '    Metadata:',
 '      handler_name    : VideoHandle',
 '    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)',
 '    Metadata:',
 '      handler_name    : SoundHandle',
 'At least one output file must be specified']

How can I preserve this functionality but by having the path stored in a variable? I don't want to use subprocess because I want to store the output of meta in a variable.

connor449
  • 1,549
  • 2
  • 18
  • 49

2 Answers2

1

You can use the following:

path = 'video.mp4'
meta = !ffmpeg -i $path
jkr
  • 17,119
  • 2
  • 42
  • 68
1

Use curly braces around the variable name to force variable interpolation :

path = 'video.mp4'
meta = !ffmpeg -i {path}
joao
  • 2,220
  • 2
  • 11
  • 15