FFmpeg v4l2m2m的capture和output

发现FFmpeg v4l2m2m中encoder和decoder中的output和capture的细节,理解起来有点奇怪,记录如下。

encoder v4l2_encode_init

external/ffmpeg/ffmpeg/libavcodec/v4l2_m2m_enc.c

    /* output context */
    output->av_codec_id = AV_CODEC_ID_RAWVIDEO;
    output->av_pix_fmt = avctx->pix_fmt;

    /* capture context */
    capture->av_codec_id = avctx->codec_id;
    capture->av_pix_fmt = AV_PIX_FMT_NONE;

decoder v4l2_decode_init

external/ffmpeg/ffmpeg/libavcodec/v4l2_m2m_dec.c

  
    /* output context */
    output->av_codec_id = avctx->codec_id;
    output->av_pix_fmt  = AV_PIX_FMT_NONE;

    /* capture context */
    capture->av_codec_id = AV_CODEC_ID_RAWVIDEO;
    capture->av_pix_fmt = avctx->pix_fmt;

在编码器encoder中,capture对应输出编码后的视频数据,而output对应的是输入原始视频数据。编码器的主要作用是将原始视频数据压缩成指定codec格式的数据流,以便于传输和存储。

在解码器decoder中,capture对应的是解码后的视频数据,而output对应的是输入的原始视频数据。解码器的主要作用是将编码后的视频数据解压缩成原始视频数据,以便于播放和处理。

这里,不管是encoder还是decoder,这个output实际上就相当于encoder或者decoder的input,不理解为什么不定义为input呢?

  • 从下面的log看,使用h264_v4l2m2m解码,输入是h264(output),输出是NM21(capture),确实在v4l2的实现里面把输入叫做output,输出叫capture
$ ffmpeg -vcodec h264_v4l2m2m -i /data/h264.mp4 -pix_fmt nv21 /data/yuv420p-1080x720.yuv -loglevel trace

[h264_v4l2m2m @ 0x1cdbaa0] probing device /dev/video26
[h264_v4l2m2m @ 0x1cdbaa0] driver 'aml-vcodec-dec' on card 'platform:amlogic' in mplane mode
[h264_v4l2m2m @ 0x1cdbaa0] Using device /dev/video26
[h264_v4l2m2m @ 0x1cdbaa0] driver 'aml-vcodec-dec' on card 'platform:amlogic' in mplane mode
[h264_v4l2m2m @ 0x1cdbaa0] requesting formats: output=H264 capture=NM21
[h264_v4l2m2m @ 0x1cdbaa0] output: H264 16 buffers initialized: 0064x0064, sizeimage 01048576, bytesperline 00000000

/dev/video的设备列表:

sh-5.1# ls /dev/video*
/dev/video10  /dev/video14  /dev/video18  /dev/video23  /dev/video32  /dev/video36           /dev/video_composer.1
/dev/video11  /dev/video15  /dev/video19  /dev/video26  /dev/video33  /dev/video37           /dev/videotunnel
/dev/video12  /dev/video16  /dev/video20  /dev/video30  /dev/video34  /dev/video38
/dev/video13  /dev/video17  /dev/video21  /dev/video31  /dev/video35  /dev/video_composer.0

对比下encoder的log输出,在当前的设备上,枚举了video设备,没有合适的设备,最后configure失败:

ffmpeg -pix_fmt nv21 -video_size 1080x720 -i /data/yuv420p-1080x720.yuv -vcodec h264_v4l2m2m /data/output.mp4 -loglevel trace

[graph 0 input from stream 0:0 @ 0xd105d0] Setting 'video_size' to value '1080x720'
[graph 0 input from stream 0:0 @ 0xd105d0] Setting 'pix_fmt' to value '24'
[graph 0 input from stream 0:0 @ 0xd105d0] Setting 'time_base' to value '1/25'
[graph 0 input from stream 0:0 @ 0xd105d0] Setting 'pixel_aspect' to value '0/1'
[graph 0 input from stream 0:0 @ 0xd105d0] Setting 'frame_rate' to value '25/1'
[graph 0 input from stream 0:0 @ 0xd105d0] w:1080 h:720 pixfmt:nv21 tb:1/25 fr:25/1 sar:0/1
[AVFilterGraph @ 0xd0fde0] query_formats: 3 queried, 2 merged, 0 already done, 0 delayed
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video26
[h264_v4l2m2m @ 0xd0dd10] driver 'aml-vcodec-dec' on card 'platform:amlogic' in mplane mode
[h264_v4l2m2m @ 0xd0dd10] v4l2 capture format not supported
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video12
[h264_v4l2m2m @ 0xd0dd10] driver 'amlvideo2' on card 'amlvideo2' in splane mode
[h264_v4l2m2m @ 0xd0dd10] v4l2 output format not supported
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video11
[h264_v4l2m2m @ 0xd0dd10] driver 'amlvideo2' on card 'amlvideo2' in splane mode
[h264_v4l2m2m @ 0xd0dd10] v4l2 output format not supported
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video23
[h264_v4l2m2m @ 0xd0dd10] driver 'amlvideo' on card 'amlvideo' in splane mode
[h264_v4l2m2m @ 0xd0dd10] v4l2 output format not supported
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video10
[h264_v4l2m2m @ 0xd0dd10] driver 'amlvideo' on card 'amlvideo' in splane mode
[h264_v4l2m2m @ 0xd0dd10] v4l2 output format not supported
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video38
[h264_v4l2m2m @ 0xd0dd10] driver 'v4lvideo' on card 'v4lvideo' in splane mode
[h264_v4l2m2m @ 0xd0dd10] v4l2 output format not supported
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video37
[h264_v4l2m2m @ 0xd0dd10] driver 'v4lvideo' on card 'v4lvideo' in splane mode
[h264_v4l2m2m @ 0xd0dd10] v4l2 output format not supported
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video36
[h264_v4l2m2m @ 0xd0dd10] driver 'v4lvideo' on card 'v4lvideo' in splane mode
[h264_v4l2m2m @ 0xd0dd10] v4l2 output format not supported
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video35
[h264_v4l2m2m @ 0xd0dd10] driver 'v4lvideo' on card 'v4lvideo' in splane mode
[h264_v4l2m2m @ 0xd0dd10] v4l2 output format not supported
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video34
[h264_v4l2m2m @ 0xd0dd10] driver 'v4lvideo' on card 'v4lvideo' in splane mode
[h264_v4l2m2m @ 0xd0dd10] v4l2 output format not supported
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video33
[h264_v4l2m2m @ 0xd0dd10] driver 'v4lvideo' on card 'v4lvideo' in splane mode
[h264_v4l2m2m @ 0xd0dd10] v4l2 output format not supported
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video32
[h264_v4l2m2m @ 0xd0dd10] driver 'v4lvideo' on card 'v4lvideo' in splane mode
[h264_v4l2m2m @ 0xd0dd10] v4l2 output format not supported
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video31
[h264_v4l2m2m @ 0xd0dd10] driver 'v4lvideo' on card 'v4lvideo' in splane mode
[h264_v4l2m2m @ 0xd0dd10] v4l2 output format not supported
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video30
[h264_v4l2m2m @ 0xd0dd10] driver 'v4lvideo' on card 'v4lvideo' in splane mode
[h264_v4l2m2m @ 0xd0dd10] v4l2 output format not supported
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video21
[h264_v4l2m2m @ 0xd0dd10] driver 'ionvideo' on card 'ionvideo' in splane mode
[h264_v4l2m2m @ 0xd0dd10] v4l2 output format not supported
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video20
[h264_v4l2m2m @ 0xd0dd10] driver 'ionvideo' on card 'ionvideo' in splane mode
[h264_v4l2m2m @ 0xd0dd10] v4l2 output format not supported
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video19
[h264_v4l2m2m @ 0xd0dd10] driver 'ionvideo' on card 'ionvideo' in splane mode
[h264_v4l2m2m @ 0xd0dd10] v4l2 output format not supported
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video18
[h264_v4l2m2m @ 0xd0dd10] driver 'ionvideo' on card 'ionvideo' in splane mode
[h264_v4l2m2m @ 0xd0dd10] v4l2 output format not supported
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video17
[h264_v4l2m2m @ 0xd0dd10] driver 'ionvideo' on card 'ionvideo' in splane mode
[h264_v4l2m2m @ 0xd0dd10] v4l2 output format not supported
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video16
[h264_v4l2m2m @ 0xd0dd10] driver 'ionvideo' on card 'ionvideo' in splane mode
[h264_v4l2m2m @ 0xd0dd10] v4l2 output format not supported
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video15
[h264_v4l2m2m @ 0xd0dd10] driver 'ionvideo' on card 'ionvideo' in splane mode
[h264_v4l2m2m @ 0xd0dd10] v4l2 output format not supported
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video14
[h264_v4l2m2m @ 0xd0dd10] driver 'ionvideo' on card 'ionvideo' in splane mode
[h264_v4l2m2m @ 0xd0dd10] v4l2 output format not supported
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video13
[h264_v4l2m2m @ 0xd0dd10] driver 'ionvideo' on card 'ionvideo' in splane mode
[h264_v4l2m2m @ 0xd0dd10] v4l2 output format not supported
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/videotunnel
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video_composer.1
[h264_v4l2m2m @ 0xd0dd10] probing device /dev/video_composer.0
[h264_v4l2m2m @ 0xd0dd10] Could not find a valid device
[h264_v4l2m2m @ 0xd0dd10] can't configure encoder

你可能感兴趣的:(ffmpeg)