I am recording videos on Jetson NX in 1280x720 50fps h265. I am doing some postprocessing on the video using OpenCV (4.4.0 Python Contrib) and trying to save in the same format, compression and so on but the produced video’s size is always way way bigger than the original one. Original 20 mins video’s size is about 500MB that becomes about 3GB. Factor x6 is too big. Do you know what pipeline, configuration should be to reduce the size of the post processed files ?
For recording I am using following code (there’s 2 cameras but I gave previously an example with only 1 video file):
The easiest OpenCV code to just read and save video is here:
import cv2
video_extension = ".mp4"
video_filename = "original.h265"
video_file = cv2.VideoCapture(video_filename)
'''
When we are using X264:
fourcc = cv2.VideoWriter_fourcc(*'X264')
Getting following error:
python read_save_video_with_compression.py
OpenCV: FFMPEG: tag 0x34363258/'X264' is not supported with codec id 27 and format 'mp4 / MP4 (MPEG-4 Part 14)'
OpenCV: FFMPEG: fallback to use tag 0x31637661/'avc1'
OpenH264 Video Codec provided by Cisco Systems, Inc.
'''
# fourcc = cv2.VideoWriter_fourcc(*'X264') # even worse, for 500MB produces 6.5GB
fourcc = cv2.VideoWriter_fourcc(*'avc1')
output = cv2.VideoWriter(video_filename + "_post" + video_extension, fourcc, 50, (720, 1280))
while video_file.isOpened():
ret, frame = video_file.read()
if ret == None or ret == False:
break
cv2.imshow(winname=video_filename, mat=frame)
key = cv2.waitKey(1)
output.write(frame)
if (key & 0xFF) == 27:
break
cv2.destroyAllWindows()
video_file.release()
output.release()
Hi,
Please try eenav’s suggestion to set bitrate in gst-launch-1.0 command. If your source runs in steady frame rate, the bitrate should be close to the setting.
Looks like it uses software codec in the OpenCV code. For using hardware encoding/decoding, you can refer to this sample:
Hi, i ran that example and it gave me the next error:
Failed to query video capabilities: Inappropriate ioctl for device
libv4l2: error getting capabilities: Inappropriate ioctl for device
[ WARN:0] global /home/jebi/jebios/tools/wiracocha/libraries/opencv/modules/videoio/src/cap_gstreamer.cpp (1759) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module nvv4l2h264enc0 reported: Error getting capabilities for device ‘/dev/nvhost-msenc’: It isn’t a v4l2 driver. Check if it is a v4l1 driver.
[ WARN:0] global /home/jebi/jebios/tools/wiracocha/libraries/opencv/modules/videoio/src/cap_gstreamer.cpp (1759) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module nvv4l2h264enc0 reported: Could not initialize supporting library.
[ WARN:0] global /home/jebi/jebios/tools/wiracocha/libraries/opencv/modules/videoio/src/cap_gstreamer.cpp (1592) open OpenCV | GStreamer warning: GStreamer: cannot put pipeline to play
I am working on Jetson AGX Xavier, Jetpack 4.4 DP, I compiled Opencv 4.3 with ffmpeg support, this is my script of compilation:
cmake …/ -DBUILD_EXAMPLES=false -DBUILD_TESTS=false -DWITH_VTK=false -DBUILD_JAVA=false -DWITH_LIBREALSENSE=true
-DBUILD_JASPER=false -DBUILD_opencv_dnn=false -DBUILD_TESTS=false -DBUILD_PERF_TESTS=false -DWITH_V4L=Yes -DWITH_LIBV4L=yes
-DBUILD_opencv_python2=false -DBUILD_opencv_python3=true
Finally, it grabs video files with size 0. How could I resolve this issue?
Thanks