昨天用 ubuntu 20.04 安裝的 ffmpeg 進行視頻轉碼時,出現了一個奇葩的問題,用命令行能過的指令,經過 Java 調用死活不行。原來Java 調用的默認容許協議與命令行的居然不同(至於爲何不同,尚未找到答案...)。linux
ffmpeg version 4.2.2-1ubuntu1 Copyright (c) 2000-2019 the FFmpeg developers built with gcc 9 (Ubuntu 9.3.0-3ubuntu1) configuration: --prefix=/usr --extra-version=1ubuntu1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass - -enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libf ribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-l ibpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable -libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable -libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec 61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared libavutil 56. 31.100 / 56. 31.100 libavcodec 58. 54.100 / 58. 54.100 libavformat 58. 29.100 / 58. 29.100 libavdevice 58. 8.100 / 58. 8.100 libavfilter 7. 57.100 / 7. 57.100 libavresample 4. 0. 0 / 4. 0. 0 libswscale 5. 5.100 / 5. 5.100 libswresample 3. 5.100 / 3. 5.100 libpostproc 55. 5.100 / 55. 5.100 "https://video.example.com/video/ece851398dba2dc26df0e9ccba7fbe00/MULTI-ece851398dba2dc26df0e9ccba7fbe00-130961929/videos_200.mp4": No such file or directory
這個No such file or directory
根本不是文件不存在,下載到本地也會報一樣的錯web
經過'ffmpeg -loglevel debug' 首先增長調試參數。
你會看到錯誤輸出:ubuntu
ffmpeg version 4.2.2-1ubuntu1 Copyright (c) 2000-2019 the ... Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'. 0-130961929/videos_200.mp4"'. Reading option '-vcodec' ... matched as option 'vcodec' (force video codec ('copy' to copy stream)) with argument 'libwebp'. Reading option '-lossless' ... matched as AVOption 'lossless' with argument '0'. Reading option '-qscale' ... matched as option 'qscale' (use fixed quality scale (VBR)) with argument '75'. Reading option '-preset' ... matched as AVOption 'preset' with argument 'default'. Reading option '-loop' ... matched as AVOption 'loop' with argument '0'. Reading option '-an' ... matched as option 'an' (disable audio) with argument '1'. Reading option '-vsync' ... matched as option 'vsync' (video sync method) with argument '0'. Reading option '/tmp/output.webp' ... matched as output url. Finished splitting the commandline. Parsing a group of options: global . Applying option loglevel (set logging level) with argument debug. Applying option vsync (video sync method) with argument 0. Successfully parsed a group of options. Parsing a group of options: input url "https://video.example.com/video/ece851398dba2dc26df0e9ccba7fbe00/MULTI-ece851398dba2dc26df0e9ccba7fbe00-130961929/videos_200 .mp4". Applying option c (codec name) with argument /bin/sh. Successfully parsed a group of options. Opening an input file: "https://video.example.com/video/ece851398dba2dc26df0e9ccba7fbe00/MULTI-ece851398dba2dc26df0e9ccba7fbe00-130961929/videos_200.mp4". [NULL @ 0x55fd7533f440] Opening '"https://video.example.com/video/ece851398dba2dc26df0e9ccba7fbe00/MULTI-ece851398dba2dc26df0e9ccba7fbe00-130961929/videos_200.mp4" ' for reading [file @ 0x55fd7533fec0] Setting default whitelist 'file,crypto' "https://video.example.com/video/ece851398dba2dc26df0e9ccba7fbe00/MULTI-ece851398dba2dc26df0e9ccba7fbe00-130961929/videos_200.mp4": No such file or directory
這裏最重要的信息是app
Setting default whitelist 'file,crypto'
在搜索過程如下兩個連接很是有幫助:less
https://blog.yo1.dog/fix-for-...ssh
https://stackoverflow.com/a/1...tcp
能夠經過參數 '-report' 將完整的命令行和控制檯輸出轉儲到當前目錄中名爲 program-YYYYMMDD-HHMMSS.log 的文件中。該文件對於調試錯誤頗有用。它默認爲-loglevel verbose
級別的日誌輸出。也能夠經過設置FFREPORT
環境變量來實現一樣的效果:ide
FFREPORT="level=32:file=abc.log" ffmpeg -v verbose ...
如下是上面第一個連接的翻譯:svg
使用-safe 0
和-protocol_whitelist file,http,https,tcp,tls
參數。完整示例在最底部。oop
我試圖像這樣使用FFmpeg的concat多路分配器:
# inputs.txt file 'http://www.example1.com/video1.mp4' file 'https://www.example2.com/video2.mp4'
ffmpeg -f "concat" -i "./inputs.txt" -codec "copy" "./concated.mp4"
首先我獲得了錯誤:
[concat @ 0x00] Unsafe file name 'http://www.example1.com/video1.mp4' ./inputs.txt: Operation not permitted
這經過添加-safe 0
參數來解決。而後我獲得了錯誤:
[http @ 0x00] Protocol not on whitelist 'file,crypto'! [concat @ 0x00] Impossible to open 'http://www.example1.com/video1.mp4' ./inputs.txt: Invalid argument
我覺得我能夠經過簡單的添加來解決這個問題,-protocol_whitelist file,http,https
可是錯誤變成了:
[tcp @ 0x00] Protocol not on whitelist 'file,http,https'! [concat @ 0x00] Impossible to open 'http://www.example1.com/video1.mp4' ./inputs.txt: Invalid argument
我不明白爲何個人HTTP協議輸入仍然被拒絕。http
顯然在協議白名單中。而後,我注意到前兩個錯誤之間的差異很小。看那些錯誤中的第一個單詞。http
VS tcp
。我意識到錯誤以前括號中的第一個單詞是被拒絕的協議。
解決方案是也要添加tcp
到協議白名單中(tls
若是要支持HTTPS ,也要添加到協議白名單中)。這是個人最終命令:
ffmpeg -f "concat" -safe "0" -protocol_whitelist "file,http,https,tcp,tls" -i "./inputs.txt" -codec "copy" "./concated.mp4"