LoginSignup
5
9

More than 3 years have passed since last update.

ffmpeg のバックグラウンド実行時のエラーを解決する

Last updated at Posted at 2020-10-03

環境

os:ubuntu18.0.4(ec2:g4.xlarge)
Python:3.7.7
ffmpeg:4.3.1

結論

ffmpeg をバックグラウンドのプロセスで実行する時は -nostdinオプションを追加する。

cmd = f'ffmpeg -nostdin -y -i "{mv_input_path}" -vcodec h264_nvenc "{mv_ffmpeg_path}"'
subprocess.call(cmd, shell=True)

背景

アップロードされた動画をcv2で処理したあと、ffmpeg を用いて変換・圧縮し s3 に保存するというプログラムを作成しました。
プログラムをデーモン化したところ、ffmpegInvalid data found when processing input エラーが発生しました。


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!

変換は実行されているようですが、dup=76にあるように 76/83 frame が複製されています。動画を再生すると 1fps の動画になっているようです。検証した結果、デーモン化した場合にのみこのエラーが生じるようです。あれやこれや手を尽くした結果、ffmpeg を使うだけのDockerを作成して変換を行うことでいったんはなんとか解決できました。しかし、先に述べたように-nostdinオプションをつけるだけで解決できました。。。
同様の記事が全くなく、このオプションを見つけるためだけに物凄い時間を費やしたので共有いたします。

参考

5
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
9