MoviePY在使用Amazon弹性容器服务运行时出现错误。

huangapple go评论103阅读模式
英文:

MoviePY error when running in Docker Container using Amazon Elastic Container Service

问题

I'm developing a script that generates a video with the information provided by the user using Moviepy. The application runs in a docker container.

In my test environment (locally) the application usually runs generating the videos as expected. However, when I deploy to the Amazon Elastic Container Instance environment, the application renders the following error:

  1. /tmp/334.mp31boi_q7b: Invalid data found when processing input
  2. Here are the file infos returned by ffmpeg:
  3. ffmpeg version 4.2.2-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2019 the FFmpeg developers
  4. built with gcc 8 (Debian 8.3.0-6)
  5. libpostproc 55. 5.100 / 55. 5.100
  6. libswresample 3. 5.100 / 3. 5.100
  7. libswscale 5. 5.100 / 5. 5.100
  8. libavfilter 7. 57.100 / 7. 57.100
  9. libavdevice 58. 8.100 / 58. 8.100
  10. libavformat 58. 29.100 / 58. 29.100
  11. libavcodec 58. 54.100 / 58. 54.100
  12. libavutil 56. 31.100 / 56. 31.100
  13. configuration:
  14. --enable-gpl
  15. --enable-version3
  16. --enable-static
  17. --disable-debug
  18. --disable-ffplay
  19. --disable-indev=sndio
  20. --disable-outdev=sndio
  21. --cc=gcc
  22. --enable-fontconfig
  23. --enable-frei0r
  24. --enable-gnutls
  25. --enable-gmp
  26. --enable-libgme
  27. --enable-gray
  28. --enable-libaom
  29. --enable-libfribidi
  30. --enable-libass
  31. --enable-libvmaf
  32. --enable-libfreetype
  33. --enable-libmp3lame
  34. --enable-libopencore-amrnb
  35. --enable-libopencore-amrwb
  36. --enable-libopenjpeg
  37. --enable-librubberband
  38. --enable-libsoxr
  39. --enable-libspeex
  40. --enable-libsrt
  41. --enable-libvorbis
  42. --enable-libopus
  43. --enable-libtheora
  44. --enable-libvidstab
  45. --enable-libvo-amrwbenc
  46. --enable-libvpx
  47. --enable-libwebp
  48. --enable-libx264
  49. --enable-libx265
  50. --enable-libxml2
  51. --enable-libdav1d
  52. --enable-libxvid
  53. --enable-libzvbi
  54. --enable-libzimg
  55. OSError: MoviePy error: failed to read the duration of file /tmp/334.mp31boi_q7b.

To retrieve files sent by the user, I use tempfile.NamedTemporaryFile and manipulate them in memory. I make some slices in the audio to synchronize with images (as if they were slides) and to concatenate them I use the following:

  1. audio_concat = concatenate_audioclips(audio_clips)

and at the end, I generate the video as follows:

  1. with tempfile.NamedTemporaryFile(prefix=video_path, suffix='', delete=False) as data:
  2. video.write_videofile(data.name, fps=24, codec="libx264", ffmpeg_params=['-f', 'mp4'], threads=multiprocessing.cpu_count())

As said, everything works fine in the container locally, but the same does not happen in ECS.

Does anyone have any idea what I might be doing wrong?

My Dockerfile

  1. FROM ubuntu:latest
  2. ENV DEBIAN_FRONTEND noninteractive
  3. WORKDIR /video_composer
  4. COPY requirements.txt /video_composer/requirements.txt
  5. RUN apt-get update && apt-get install -y software-properties-common gcc && \
  6. add-apt-repository -y ppa:deadsnakes/ppa
  7. RUN apt-get update && apt-get install -y python3.11 python3-distutils python3-pip python3-apt
  8. RUN apt-get -y update
  9. RUN apt-get install -y ffmpeg
  10. RUN pip install -r /video_composer/requirements.txt
  11. RUN python3 -m certifi
  12. COPY . /video_composer/
  13. EXPOSE 8003
  14. CMD ["uvicorn", "video_composer:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "8003"]

Some solutions consulted and no success

https://stackoverflow.com/questions/42121508/moviepy-unable-to-read-duration-of-file

https://github.com/Zulko/moviepy/issues/116

When trying to execute the mentioned solutions I continued to have the same error in the ECS but without errors locally.

英文:

I'm developing a script that generates a video with the information provided by the user using Moviepy. The application runs in a docker container.

In my test environment (locally) the application usually runs generating the videos as expected. However, when I deploy to the Amazon Elastic Container Instance environment, the application renders the following error:

  1. /tmp/334.mp31boi_q7b: Invalid data found when processing input
  2. Here are the file infos returned by ffmpeg:
  3. ffmpeg version 4.2.2-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2019 the FFmpeg developers
  4. built with gcc 8 (Debian 8.3.0-6)
  5. libpostproc 55. 5.100 / 55. 5.100
  6. libswresample 3. 5.100 / 3. 5.100
  7. libswscale 5. 5.100 / 5. 5.100
  8. libavfilter 7. 57.100 / 7. 57.100
  9. libavdevice 58. 8.100 / 58. 8.100
  10. libavformat 58. 29.100 / 58. 29.100
  11. libavcodec 58. 54.100 / 58. 54.100
  12. libavutil 56. 31.100 / 56. 31.100
  13. configuration:
  14. --enable-gpl
  15. --enable-version3
  16. --enable-static
  17. --disable-debug
  18. --disable-ffplay
  19. --disable-indev=sndio
  20. --disable-outdev=sndio
  21. --cc=gcc
  22. --enable-fontconfig
  23. --enable-frei0r
  24. --enable-gnutls
  25. --enable-gmp
  26. --enable-libgme
  27. --enable-gray
  28. --enable-libaom
  29. --enable-libfribidi
  30. --enable-libass
  31. --enable-libvmaf
  32. --enable-libfreetype
  33. --enable-libmp3lame
  34. --enable-libopencore-amrnb
  35. --enable-libopencore-amrwb
  36. --enable-libopenjpeg
  37. --enable-librubberband
  38. --enable-libsoxr
  39. --enable-libspeex
  40. --enable-libsrt
  41. --enable-libvorbis
  42. --enable-libopus
  43. --enable-libtheora
  44. --enable-libvidstab
  45. --enable-libvo-amrwbenc
  46. --enable-libvpx
  47. --enable-libwebp
  48. --enable-libx264
  49. --enable-libx265
  50. --enable-libxml2
  51. --enable-libdav1d
  52. --enable-libxvid
  53. --enable-libzvbi
  54. --enable-libzimg
  55. OSError: MoviePy error: failed to read the duration of file /tmp/334.mp31boi_q7b.

To retrieve files sent by the user, I use tempfile.NamedTemporaryFile and manipulate them in memory. I make some slices in the audio to synchronize with images (as if they were slides) and to concatenate them I use the following:

  1. audio_concat = concatenate_audioclips(audio_clips)

and at the end, I generate the video as follows:

  1. with tempfile.NamedTemporaryFile(prefix=video_path, suffix='', delete=False) as data:
  2. video.write_videofile(data.name, fps=24, codec="libx264", ffmpeg_params=['-f', 'mp4'], threads=multiprocessing.cpu_count())

As said, everything works fine in the container locally, but the same does not happen in ECS.

Does anyone have any idea what I might be doing wrong?

My Dockerfile

  1. FROM ubuntu:latest
  2. ENV DEBIAN_FRONTEND noninteractive
  3. WORKDIR /video_composer
  4. COPY requirements.txt /video_composer/requirements.txt
  5. RUN apt-get update && apt-get install -y software-properties-common gcc && \
  6. add-apt-repository -y ppa:deadsnakes/ppa
  7. RUN apt-get update && apt-get install -y python3.11 python3-distutils python3-pip python3-apt
  8. RUN apt-get -y update
  9. RUN apt-get install -y ffmpeg
  10. RUN pip install -r /video_composer/requirements.txt
  11. RUN python3 -m certifi
  12. COPY . /video_composer/
  13. EXPOSE 8003
  14. CMD ["uvicorn", "video_composer:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "8003"]

Some solutions consulted and no success

https://stackoverflow.com/questions/42121508/moviepy-unable-to-read-duration-of-file

https://github.com/Zulko/moviepy/issues/116

When trying to execute the mentioned solutions I continued to have the same error in the ECS but without errors locally.

答案1

得分: 0

在经过大量代码调试后,我已经找到了问题所在。我使用了一个异步服务来生成用于视频的音频。偶尔,音频生成过程会变得更长,由于我的疏忽,在使用音频之前未能进行验证。

因此,在我的情况下,会出现错误 OSError: MoviePy error: failed to read the duration of file /tmp/334.mp31boi_q7b. ,这是因为音频文件为空。就是这样!

在本地运行音频时,生成过程中的延迟非常小,这就是为什么本地没有出现问题的原因。

英文:

after extensive code debugging, I have identified the issue. I utilize an asynchronous service that generates audio to be used in the video. Occasionally, the audio generation process took longer, and due to my oversight, I failed to verify before utilizing the audio.

Therefore, the error OSError: MoviePy error: failed to read the duration of file /tmp/334.mp31boi_q7b.
occurs (in my case) because the audio file was empty. That's it!

When running the audio locally, the latency in the generation process was minimal, which is why no issues occurred locally.

huangapple
  • 本文由 发表于 2023年5月14日 21:28:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76247724.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定