# import the necessary packages
from deffcode import FFdecoder
import cv2
# define suitable FFmpeg parameter
ffparams = {
"-vcodec": "h264_nvmpi", # use H.264 CUVID Video-decoder
"-enforce_cv_patch": True # enable OpenCV patch for YUV(YUV420p) frames
}
# initialize and formulate the decoder with `foo.mp4` source
decoder = FFdecoder(
"demo.mp4",
frame_format="yuv420p", # use YUV420p frame pixel format
verbose=True, # enable verbose output
**ffparams # apply various params and custom filters
).formulate()
# grab the YUV420p frame from the decoder
for frame in decoder.generateFrame():
# check if frame is None
if frame is None:
break
# convert it to `BGR` pixel format,
# since imshow() method only accepts `BGR` frames
frame = cv2.cvtColor(frame, cv2.COLOR_YUV2BGR_I420)
# {do something with the BGR frame here}
# Show output window
cv2.imshow("Output", frame)
# check for 'q' key if pressed
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break
# close output window
cv2.destroyAllWindows()
# terminate the decoder
decoder.terminate()
In file included from libavcodec/nvv4l2_dec.c:44:
/usr/src/jetson_multimedia_api/include/libv4l2.h:30:5: warning: "HAVE_VISIBILITY" is not defined, evaluates to 0 [-Wundef]
30 | #if HAVE_VISIBILITY
| ^~~~~~~~~~~~~~~
CC libavcodec/opus.o
CC libavcodec/options.o
In file included from libavcodec/nvv4l2_dec.c:56:
libavcodec/v4l2_nv_extensions.h:195:8: error: redefinition of ‘struct v4l2_ctrl_h264_sps’
195 | struct v4l2_ctrl_h264_sps {
| ^~~~~~~~~~~~~~~~~~
In file included from /usr/include/linux/videodev2.h:65,
from libavcodec/nvv4l2_dec.c:45:
/usr/include/linux/v4l2-controls.h:1306:8: note: originally defined here
1306 | struct v4l2_ctrl_h264_sps {
| ^~~~~~~~~~~~~~~~~~
In file included from libavcodec/nvv4l2_dec.c:56:
libavcodec/v4l2_nv_extensions.h:224:8: error: redefinition of ‘struct v4l2_ctrl_h264_pps’
224 | struct v4l2_ctrl_h264_pps {
| ^~~~~~~~~~~~~~~~~~
In file included from /usr/include/linux/videodev2.h:65,
from libavcodec/nvv4l2_dec.c:45:
/usr/include/linux/v4l2-controls.h:1362:8: note: originally defined here
1362 | struct v4l2_ctrl_h264_pps {
| ^~~~~~~~~~~~~~~~~~
In file included from libavcodec/nvv4l2_dec.c:56:
libavcodec/v4l2_nv_extensions.h:238:8: error: redefinition of ‘struct v4l2_ctrl_h264_scaling_matrix’
238 | struct v4l2_ctrl_h264_scaling_matrix {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/linux/videodev2.h:65,
from libavcodec/nvv4l2_dec.c:45:
/usr/include/linux/v4l2-controls.h:1394:8: note: originally defined here
1394 | struct v4l2_ctrl_h264_scaling_matrix {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from libavcodec/nvv4l2_dec.c:56:
libavcodec/v4l2_nv_extensions.h:243:8: error: redefinition of ‘struct v4l2_h264_weight_factors’
243 | struct v4l2_h264_weight_factors {
| ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/linux/videodev2.h:65,
from libavcodec/nvv4l2_dec.c:45:
/usr/include/linux/v4l2-controls.h:1399:8: note: originally defined here
1399 | struct v4l2_h264_weight_factors {
| ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from libavcodec/nvv4l2_dec.c:56:
libavcodec/v4l2_nv_extensions.h:304: warning: "V4L2_H264_DPB_ENTRY_FLAG_ACTIVE" redefined
304 | #define V4L2_H264_DPB_ENTRY_FLAG_ACTIVE 0x01
|
In file included from /usr/include/linux/videodev2.h:65,
from libavcodec/nvv4l2_dec.c:45:
/usr/include/linux/v4l2-controls.h:1521: note: this is the location of the previous definition
1521 | #define V4L2_H264_DPB_ENTRY_FLAG_ACTIVE 0x02
|
In file included from libavcodec/nvv4l2_dec.c:56:
libavcodec/v4l2_nv_extensions.h:305: warning: "V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM" redefined
305 | #define V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM 0x02
|
In file included from /usr/include/linux/videodev2.h:65,
from libavcodec/nvv4l2_dec.c:45:
/usr/include/linux/v4l2-controls.h:1522: note: this is the location of the previous definition
1522 | #define V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM 0x04
|
In file included from libavcodec/nvv4l2_dec.c:56:
libavcodec/v4l2_nv_extensions.h:306:8: error: redefinition of ‘struct v4l2_h264_dpb_entry’
306 | struct v4l2_h264_dpb_entry {
| ^~~~~~~~~~~~~~~~~~~
In file included from /usr/include/linux/videodev2.h:65,
from libavcodec/nvv4l2_dec.c:45:
/usr/include/linux/v4l2-controls.h:1542:8: note: originally defined here
1542 | struct v4l2_h264_dpb_entry {
| ^~~~~~~~~~~~~~~~~~~
libavcodec/nvv4l2_dec.c: In function ‘query_set_capture’:
libavcodec/nvv4l2_dec.c:589:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
589 | NvBufSurface *nvbuf_surf = 0;
| ^~~~~~~~~~~~
libavcodec/nvv4l2_dec.c:698:13: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
698 | NvBufSurface *nvbuf_surf_dest = 0;
| ^~~~~~~~~~~~
libavcodec/nvv4l2_dec.c: In function ‘capture_thread’:
libavcodec/nvv4l2_dec.c:873:13: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
873 | NvBufSurface *decoded_nvbuf_surf = 0;
| ^~~~~~~~~~~~
libavcodec/nvv4l2_dec.c:885:13: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
885 | NvBufSurface *nvbuf_surf_parm = 0;
| ^~~~~~~~~~~~
libavcodec/nvv4l2_dec.c:917:13: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
917 | NvBufSurface *nvbuf_surf = NULL;
| ^~~~~~~~~~~~
make: *** [ffbuild/common.mak:59: libavcodec/nvv4l2_dec.o] Error 1
make: *** Waiting for unfinished jobs....
libavcodec/options.c: In function ‘codec_child_class_next’:
libavcodec/options.c:61:5: warning: ‘av_codec_next’ is deprecated [-Wdeprecated-declarations]
61 | while (prev && (c = av_codec_next(c)))
| ^~~~~
In file included from libavcodec/options.c:27:
libavcodec/avcodec.h:4118:10: note: declared here
4118 | AVCodec *av_codec_next(const AVCodec *c);
| ^~~~~~~~~~~~~
libavcodec/options.c:66:5: warning: ‘av_codec_next’ is deprecated [-Wdeprecated-declarations]
66 | while (c = av_codec_next(c))
| ^~~~~
In file included from libavcodec/options.c:27:
libavcodec/avcodec.h:4118:10: note: declared here
4118 | AVCodec *av_codec_next(const AVCodec *c);
| ^~~~~~~~~~~~~
@DaneLLL I’m using 6.0DP with AGX Orin 64gb.
I got it with gstreamer, but please check with ffmpeg because it doesn’t compile for me.
and apt’s ffmpeg is compiled without jetson’s hw accelerators.