0
import subprocess
ffmpeg_params=['ffmpeg', '-y', '-i', 'http://cache.m.iqiyi.com/mus/235133201/2af150aebb98276a80d52513fb91fbc8/afbe8fd3d73448c9/0/20210115/1f/c5/cda301a0e8339c4cbcc89a4e9a6dafac.m3u8?qd_originate=tmts_py&tvid=1694459300&bossStatus=0&qd_vip=0&px=&src=3_31_312&prv=&previewType=&previewTime=&from=&qd_time=1612598784271&qd_p=6011968c&qd_asc=d0d83b774212c40885a78123935cf7d4&qypid=1694459300_04022000001000000000_4&qd_k=7b1dacf9d318a810bd201e367ef98196&isdol=0&code=2&ff=f4v&iswb=0&qd_s=otv&vf=bb7741a4e27350139427f0051c641530&np_tag=nginx_part_tag', '-c', 'copy', '-bsf:a', 'aac_adtstoasc', '--', 'f:\\/【英语口语】我羡慕你.mp4']
b=subprocess.Popen(ffmpeg_params)

Using this simple .py script I can call ffmpeg to download the video file sucessfully.

However, if I run

ffmpeg -y -i http://cache.m.iqiyi.com/mus/235133201/2af150aebb98276a80d52513fb91fbc8/afbe8fd3d73448c9/0/20210115/1f/c5/cda301a0e8339c4cbcc89a4e9a6dafac.m3u8?qd_originate=tmts_py&tvid=1694459300&bossStatus=0&qd_vip=0&px=&src=3_31_312&prv=&previewType=&previewTime=&from=&qd_time=1612598784271&qd_p=6011968c&qd_asc=d0d83b774212c40885a78123935cf7d4&qypid=1694459300_04022000001000000000_4&qd_k=7b1dacf9d318a810bd201e367ef98196&isdol=0&code=2&ff=f4v&iswb=0&qd_s=otv&vf=bb7741a4e27350139427f0051c641530&np_tag=nginx_part_tag -c copy -bsf:a aac_adtstoasc -- f:/【英语口语】我羡慕你.mp4

in shell, it will fail with below message:

ffmpeg version N-90173-gfa0c9d69d3 Copyright (c) 2000-2018 the FFmpeg developers built with gcc 7.3.0 (GCC) configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libmfx --enable-amf --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth libavutil 56. 7.101 / 56. 7.101 libavcodec 58. 13.100 / 58. 13.100 libavformat 58. 10.100 / 58. 10.100 libavdevice 58. 2.100 / 58. 2.100 libavfilter 7. 12.100 / 7. 12.100 libswscale 5. 0.101 / 5. 0.101 libswresample 3. 0.101 / 3. 0.101 libpostproc 55. 0.100 / 55. 0.100 http://cache.m.iqiyi.com/mus/235133201/2af150aebb98276a80d52513fb91fbc8/afbe8fd3d73448c9/0/20210115/1f/c5/cda301a0e8339c4cbcc89a4e9a6dafac.m3u8?qd_originate=tmts_py: Invalid data found when processing input 'tvid' is not recognized as an internal or external command, operable program or batch file. 'bossStatus' is not recognized as an internal or external command, operable program or batch file.

I can use subprocess.Popen to call the ffmpeg to download the video file successfully, However, I can't directly run ffmpeg in shell with the same parameters to download the file. Why? How can I directly run ffmpeg in shell to download the file?

1 Answers1

0

The shell is interpreting the '&' character in your URL ('tvid', 'bossStatus', etc are parameters in the URL), interrupting the ffmpeg command and trying to start a new command. With subprocess you don't have this issue, the command and its arguments are safely separated.

To run it in the shell you need to enclose the URL in double quotes:

ffmpeg -y -i "http://cache.m.iqiyi.com/mus/235133201/2af150aebb98276a80d52513fb91fbc8/afbe8fd3d73448c9/0/20210115/1f/c5/cda301a0e8339c4cbcc89a4e9a6dafac.m3u8?qd_originate=tmts_py&tvid=1694459300&bossStatus=0&qd_vip=0&px=&src=3_31_312&prv=&previewType=&previewTime=&from=&qd_time=1612598784271&qd_p=6011968c&qd_asc=d0d83b774212c40885a78123935cf7d4&qypid=1694459300_04022000001000000000_4&qd_k=7b1dacf9d318a810bd201e367ef98196&isdol=0&code=2&ff=f4v&iswb=0&qd_s=otv&vf=bb7741a4e27350139427f0051c641530&np_tag=nginx_part_tag -c copy -bsf:a aac_adtstoasc -- f:/【英语口语】我羡慕你.mp4"
joao
  • 2,220
  • 2
  • 11
  • 15
  • Yes, it works as your method. Thanks a lot! – hu chenlin Feb 06 '21 at 09:36
  • Actually, before I post this question, I've tried single quotes, but it can't work in CMD. So single quotes are quite different from double quotes in CMD. This is the main lesson I learned. – hu chenlin Feb 06 '21 at 10:02
  • You tagged your question [tag:shell] which generally implies a Unix shell. Use [tag:cmd] if that's what you need help with. Single quotes are better in Unix, but double quotes happen to work here, too, as long as the string does not contain any dollar signs, backticks, backslashes, or literal double quotes. In `cmd`, double quotes is the only game in town, but there are other complications, many of them horribly bewildering. – tripleee Feb 06 '21 at 12:39