diff mbox series

[FFmpeg-devel,1/2] avdevice/v4l2: add support for HEVC payloads

Message ID 20200715065057.548738-1-dima.buzdyk@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/2] avdevice/v4l2: add support for HEVC payloads
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Dima Buzdyk July 15, 2020, 6:50 a.m. UTC
* Add mapping for V4L2_PIX_FMT_HEVC payloads
* Request bitstream parsing just like H264

Signed-off-by: Dima Buzdyk <dima.buzdyk@gmail.com>
---
 libavdevice/v4l2-common.c | 3 +++
 libavdevice/v4l2.c        | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

This change add support for HEVC playback for v4l2 devices.

Corresponding Linux kernel patch for UVC devices submitted to
https://patchwork.kernel.org/patch/11577395/

Sample output of ffmpeg for camera capable of HEVC streaming:
1. Available formats:
    ~/packages/ffmpeg/ffmpeg-git$ ./ffmpeg -f v4l2 -list_formats all -i /dev/video2
    ffmpeg version 4.3.git Copyright (c) 2000-2020 the FFmpeg developers
      built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
      configuration: 
      libavutil      56. 55.100 / 56. 55.100
      libavcodec     58. 96.100 / 58. 96.100
      libavformat    58. 48.100 / 58. 48.100
      libavdevice    58. 11.101 / 58. 11.101
      libavfilter     7. 87.100 /  7. 87.100
      libswscale      5.  8.100 /  5.  8.100
      libswresample   3.  8.100 /  3.  8.100
    [video4linux2,v4l2 @ 0x55c04e131700] Compressed:        h264 :                H.264 : 1440x1920
    [video4linux2,v4l2 @ 0x55c04e131700] Compressed:        hevc :                 HEVC : 1440x1920
    [video4linux2,v4l2 @ 0x55c04e131700] Compressed:       mjpeg :          Motion-JPEG : 3000x4000
    /dev/video2: Immediate exit requested

2. ffprobe output for given input format:
    ~/packages/ffmpeg/ffmpeg-git$ ./ffprobe -f v4l2 -input_format hevc -i /dev/video2
    ffprobe version 4.3.git Copyright (c) 2007-2020 the FFmpeg developers
      built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
      configuration: 
      libavutil      56. 55.100 / 56. 55.100
      libavcodec     58. 96.100 / 58. 96.100
      libavformat    58. 48.100 / 58. 48.100
      libavdevice    58. 11.101 / 58. 11.101
      libavfilter     7. 87.100 /  7. 87.100
      libswscale      5.  8.100 /  5.  8.100
      libswresample   3.  8.100 /  3.  8.100
    Input #0, video4linux2,v4l2, from '/dev/video2':
      Duration: N/A, start: 416791.927897, bitrate: N/A
        Stream #0:0: Video: hevc (Main), yuv420p(tv), 1440x1920, 30 fps, 30 tbr, 1000k tbn, 29.97 tbc
diff mbox series

Patch

diff --git a/libavdevice/v4l2-common.c b/libavdevice/v4l2-common.c
index b5b4448a31..353e83efdd 100644
--- a/libavdevice/v4l2-common.c
+++ b/libavdevice/v4l2-common.c
@@ -55,6 +55,9 @@  const struct fmt_map ff_fmt_conversion_table[] = {
 #ifdef V4L2_PIX_FMT_H264
     { AV_PIX_FMT_NONE,    AV_CODEC_ID_H264,     V4L2_PIX_FMT_H264    },
 #endif
+#ifdef V4L2_PIX_FMT_HEVC
+    { AV_PIX_FMT_NONE,    AV_CODEC_ID_HEVC,     V4L2_PIX_FMT_HEVC    },
+#endif
 #ifdef V4L2_PIX_FMT_MPEG4
     { AV_PIX_FMT_NONE,    AV_CODEC_ID_MPEG4,    V4L2_PIX_FMT_MPEG4   },
 #endif
diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index 365bacd771..70e0f620f8 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -960,7 +960,7 @@  static int v4l2_read_header(AVFormatContext *ctx)
     if (codec_id == AV_CODEC_ID_RAWVIDEO)
         st->codecpar->codec_tag =
             avcodec_pix_fmt_to_codec_tag(st->codecpar->format);
-    else if (codec_id == AV_CODEC_ID_H264) {
+    else if (codec_id == AV_CODEC_ID_H264 || codec_id == AV_CODEC_ID_HEVC) {
         st->need_parsing = AVSTREAM_PARSE_FULL_ONCE;
     }
     if (desired_format == V4L2_PIX_FMT_YVU420)