微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在守护进程中运行ffmpeg时出现错误

如何解决在守护进程中运行ffmpeg时出现错误

我正在使用subprocess.call()函数在python(3.7.7)文件中运行ffmpeg(4.3.1)。

cmd = f'ffmpeg -y -i "{mv_temp_out_path}" -vcodec h264 "{mv_ffmpeg_path}"'
# cmd = f'ffmpeg -y -i "{mv_temp_out_path}" -vcodec h264_nvenc "{mv_ffmpeg_path}"' # gpu
subprocess.call(cmd,shell=True)

但是,在gunicorn中运行python文件时,使用-D option(守护进程)运行python时出现错误。如果我不带-D选项运行它,它就可以正常工作。我想知道我是否不能使用gpu并将其设置为使用cpu时出现相同的错误

结果如下。

Input #0,mov,mp4,m4a,3gp,3g2,mj2,from './Outputs/TempSaveMovie/200703_4_short_5fr_p2(100_20)_r(50_20).mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.35.100
  Duration: 00:00:06.15,start: 0.000000,bitrate: 10246 kb/s
    Stream #0:0(und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D),yuv420p,1280x720 [SAR 1:1 DAR 16:9],10244 kb/s,13 fps,13 tbr,13312 tbn,13 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg4 (native) -> h264 (h264_nvenc))
Press [q] to stop,[?] for help
[mpeg4 @ 0x55cec17c5480] header damaged
[mpeg4 @ 0x55cec17c6840] header damaged
[mpeg4 @ 0x55cec1855f80] header damaged
[mpeg4 @ 0x55cec1866e00] header damaged
Output #0,to './Outputs/MovieOutputs/200703_4_short_5fr_p2(100_20)_r(50_20).mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.45.100
    Stream #0:0(und): Video: h264 (h264_nvenc) (Main) (avc1 / 0x31637661),q=-1--1,2000 kb/s,13 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc58.91.100 h264_nvenc
    Side data:
      cpb: bitrate max/min/avg: 0/0/2000000 buffer size: 4000000 vbv_delay: N/A
Error while decoding stream #0:0: Invalid data found when processing input
[mpeg4 @ 0x55cec17c8780] header damaged
Error while decoding stream #0:0: Invalid data found when processing input
[mpeg4 @ 0x55cec17c5480] header damaged
...
...
...
[mpeg4 @ 0x55cec1855f80] header damaged
Error while decoding stream #0:0: Invalid data found when processing input
[mpeg4 @ 0x55cec1866e00] header damaged
Error while decoding stream #0:0: Invalid data found when processing input
    Last message repeated 3 times
frame=   83 fps=0.0 q=14.0 Lsize=    1800kB time=00:00:06.30 bitrate=2337.4kbits/s dup=76 drop=0 speed=18.7x
video:1799kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.064613%
Conversion Failed!

如果有人能告诉我这件事,我将不胜感激。预先谢谢你。

后记 我对代码进行了如下修改并运行。

com = ['/usr/local/bin/ffmpeg','-y','-i','/var/www/System/Backend/Outputs/TempSaveMovie/200703_4.mp4','-vcodec','h264_nvenc','/var/www/System/Backend/Outputs/MovieOutputs/200703_4.mp4']
subprocess.call(com,shell=False)

结果如下。

ffmpeg version 4.3.1 copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --disable-shared --enable-static
  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
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
"/var/www/System/Backend/Outputs/TempSaveMovie/200703_4.mp4": No such file or directory
1
os.path.exists('/var/www/System/Backend/Outputs/TempSaveMovie/200703_4.mp4')
=> True

解决方法

使用:

subprocess.call(cmd,shell=False)

隐藏Cmd窗口

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。