Encoding error
python blur_faces.py media/friends.mp4 --mode all --censor-type pixelation
media/friends.mp4
mode='all', model='hog', censor_type='pixelation', count=1, in_face_file=None
width=1280, height=720, length=157, fps=23.976, codec='avc1'
[ERROR:[email protected]] global /io/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp (2927) open Could not find encoder for codec_id=27, error: Encoder not found
[ERROR:[email protected]] global /io/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp (3002) open VIDEOIO/FFMPEG: Failed to initialize VideoWriter
99%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▋ | 157/158 [01:13<00:00, 2.13it/s]
ffmpeg version N-114385-g4743c9e87a Copyright (c) 2000-2024 the FFmpeg developers
built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.2)
configuration: --enable-cuda-nvcc --enable-cuvid --enable-nvenc --enable-nonfree --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
libavutil 59. 7.100 / 59. 7.100
libavcodec 61. 2.100 / 61. 2.100
libavformat 61. 0.100 / 61. 0.100
libavdevice 61. 0.100 / 61. 0.100
libavfilter 10. 0.100 / 10. 0.100
libswscale 8. 0.100 / 8. 0.100
libswresample 5. 0.100 / 5. 0.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5609d1e68000] Format mov,mp4,m4a,3gp,3g2,mj2 detected only with low score of 1, misdetection possible!
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5609d1e68000] moov atom not found
[in#0 @ 0x5609d1e67cc0] Error opening input: Invalid data found when processing input
Error opening input file /tmp/tmpf9ffrai0.mp4.
Error opening input files: Invalid data found when processing input
Traceback (most recent call last):
File "blur_faces.py", line 143, in
My ffmpeg
ffmpeg -hwaccels ffmpeg version N-114385-g4743c9e87a Copyright (c) 2000-2024 the FFmpeg developers built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.2) configuration: --enable-cuda-nvcc --enable-cuvid --enable-nvenc --enable-nonfree --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64 libavutil 59. 7.100 / 59. 7.100 libavcodec 61. 2.100 / 61. 2.100 libavformat 61. 0.100 / 61. 0.100 libavdevice 61. 0.100 / 61. 0.100 libavfilter 10. 0.100 / 10. 0.100 libswscale 8. 0.100 / 8. 0.100 libswresample 5. 0.100 / 5. 0.100 Hardware acceleration methods: vdpau cuda drm
It appears that you are using Python version 3.8, as indicated by the path "/opt/BlurryFaces/src/env/lib/python3.8/site-packages/ffmpeg/_run.py". I recommend upgrading to Python version 3.10.6 to enhance compatibility and improve performance. However, please avoid upgrading to version 3.11, as it might cause compatibility issues with some of the packages you're using.
For optimizing your code, consider replacing the existing segment responsible for setting up video writing with the following lines:
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
with tempfile.NamedTemporaryFile(suffix=file_extension) as out_video_file:
video_out = cv2.VideoWriter(
out_video_file.name, fourcc, fps, (width, height))
Everything functions correctly on my end with the current setup, but the processing speed is notably slow. For instance, it took 27 minutes to run the demo. This indicates there might be room for further optimization, especially in terms of how frames are processed and written concurrently.
Consider implementing techniques such as multi-threading or utilizing more efficient libraries or algorithms for video processing, which might significantly reduce the overall processing time. Additionally, checking for hardware acceleration support (like CUDA for dlib in face recognition) could be beneficial.