ChinaFFmpeg

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 15652|回复: 2

[Linux] 设置SEI自定义信息

[复制链接]
发表于 2018-8-22 19:32:44 | 显示全部楼层 |阅读模式
API调用版:
用ffmpeg向H264中添加SEI自定义信息
http://bbs.chinaffmpeg.com/forum ... d=590&fromuid=3
(出处: ChinaFFmpeg)


在ffmpeg中设置SEI自定义信息是通过bsf来操作的,类似于mp4toannexb这样的bitstream filter;

在最新版本的ffmpeg中是可以看到已经添加了相关的滤镜:
[AppleScript] 纯文本查看 复制代码
bogon:xxx StevenLiu$ ./ffmpeg -bsfs
ffmpeg version bbs.chinaffmpeg.com孙悟空专用版 2018 the FFmpeg developers
  built with Apple LLVM version 9.1.0 (clang-902.0.39.2)
  configuration: --enable-libass --enable-opengl --enable-libx264 --enable-libmp3lame --enable-gpl --enable-nonfree --prefix=/usr/local --enable-libtesseract --enable-libspeex --enable-libfreetype --enable-libfontconfig --enable-libfdk-aac --enable-videotoolbox --enable-libxml2
  libavutil      56. 19.100 / 56. 19.100
  libavcodec     58. 22.101 / 58. 22.101
  libavformat    58. 17.101 / 58. 17.101
  libavdevice    58.  4.101 / 58.  4.101
  libavfilter     7. 26.100 /  7. 26.100
  libswscale      5.  2.100 /  5.  2.100
  libswresample   3.  2.100 /  3.  2.100
  libpostproc    55.  2.100 / 55.  2.100
Bitstream filters:
aac_adtstoasc
chomp
dump_extra
dca_core
eac3_core
extract_extradata
filter_units
h264_metadata
h264_mp4toannexb
h264_redundant_pps
hapqa_extract
hevc_metadata
hevc_mp4toannexb
imxdump
mjpeg2jpeg
mjpegadump
mp3decomp
mpeg2_metadata
mpeg4_unpack_bframes
mov2textsub
noise
null
remove_extra
text2movsub
trace_headers
vp9_metadata
vp9_raw_reorder
vp9_superframe
vp9_superframe_split


可以看到,多了很多bsf滤镜,其中h264_metadata就是对h264的metadata进行操作的,下面看一下对应的帮助:
[AppleScript] 纯文本查看 复制代码
bogon:xxx StevenLiu$ ./ffmpeg -h bsf=h264_metadata
ffmpeg version bbs.chinaffmpeg.com孙悟空专用版 Copyright (c) 2000-2018 the FFmpeg developers
  built with Apple LLVM version 9.1.0 (clang-902.0.39.2)
  configuration: --enable-libass --enable-opengl --enable-libx264 --enable-libmp3lame --enable-gpl --enable-nonfree --prefix=/usr/local --enable-libtesseract --enable-libspeex --enable-libfreetype --enable-libfontconfig --enable-libfdk-aac --enable-videotoolbox --enable-libxml2
  libavutil      56. 19.100 / 56. 19.100
  libavcodec     58. 22.101 / 58. 22.101
  libavformat    58. 17.101 / 58. 17.101
  libavdevice    58.  4.101 / 58.  4.101
  libavfilter     7. 26.100 /  7. 26.100
  libswscale      5.  2.100 /  5.  2.100
  libswresample   3.  2.100 /  3.  2.100
  libpostproc    55.  2.100 / 55.  2.100
Bit stream filter h264_metadata
    Supported codecs: h264
h264_metadata_bsf AVOptions:
  -aud               <int>        ...V....B Access Unit Delimiter NAL units (from 0 to 2) (default pass)
     pass                         ...V....B
     insert                       ...V....B
     remove                       ...V....B
  -sample_aspect_ratio <rational>   ...V....B Set sample aspect ratio (table E-1) (from 0 to 65535) (default 0/1)
  -video_format      <int>        ...V....B Set video format (table E-2) (from -1 to 7) (default -1)
  -video_full_range_flag <int>        ...V....B Set video full range flag (from -1 to 1) (default -1)
  -colour_primaries  <int>        ...V....B Set colour primaries (table E-3) (from -1 to 255) (default -1)
  -transfer_characteristics <int>        ...V....B Set transfer characteristics (table E-4) (from -1 to 255) (default -1)
  -matrix_coefficients <int>        ...V....B Set matrix coefficients (table E-5) (from -1 to 255) (default -1)
  -chroma_sample_loc_type <int>        ...V....B Set chroma sample location type (figure E-1) (from -1 to 6) (default -1)
  -tick_rate         <rational>   ...V....B Set VUI tick rate (num_units_in_tick / time_scale) (from 0 to UINT32_MAX) (default 0/1)
  -fixed_frame_rate_flag <int>        ...V....B Set VUI fixed frame rate flag (from -1 to 1) (default -1)
  -crop_left         <int>        ...V....B Set left border crop offset (from -1 to 16880) (default -1)
  -crop_right        <int>        ...V....B Set right border crop offset (from -1 to 16880) (default -1)
  -crop_top          <int>        ...V....B Set top border crop offset (from -1 to 16880) (default -1)
  -crop_bottom       <int>        ...V....B Set bottom border crop offset (from -1 to 16880) (default -1)
  -sei_user_data     <string>     ...V....B Insert SEI user data (UUID+string)
  -delete_filler     <int>        ...V....B Delete all filler (both NAL and SEI) (from 0 to 1) (default 0)
  -display_orientation <int>        ...V....B Display orientation SEI (from 0 to 3) (default pass)
     pass                         ...V....B
     insert                       ...V....B
     remove                       ...V....B
     extract                      ...V....B
  -rotate            <double>     ...V....B Set rotation in display orientation SEI (anticlockwise angle in degrees) (from -360 to 360) (default nan)
  -flip              <flags>      ...V....B Set flip in display orientation SEI (default 0)
     horizontal                   ...V....B Set hor_flip
     vertical                     ...V....B Set ver_flip




如果要添加自定义信息的话,可以用sei_user_data
下面举个例子:

[AppleScript] 纯文本查看 复制代码
bogon:xxx StevenLiu$ ./ffmpeg -i ~/Movies/objectC/facebook.mp4 -c copy -bsf:v h264_metadata=sei_user_data=086f3693-b7b3-4f2c-9653-21492feee5b8+hello -an -t 2 -y a.h264
ffmpeg version N-91602-g03fc3a68e7 Copyright (c) 2000-2018 the FFmpeg developers
  built with Apple LLVM version 9.1.0 (clang-902.0.39.2)
  configuration: --enable-libass --enable-opengl --enable-libx264 --enable-libmp3lame --enable-gpl --enable-nonfree --prefix=/usr/local --enable-libtesseract --enable-libspeex --enable-libfreetype --enable-libfontconfig --enable-libfdk-aac --enable-videotoolbox --enable-libxml2
  libavutil      56. 19.100 / 56. 19.100
  libavcodec     58. 22.101 / 58. 22.101
  libavformat    58. 17.101 / 58. 17.101
  libavdevice    58.  4.101 / 58.  4.101
  libavfilter     7. 26.100 /  7. 26.100
  libswscale      5.  2.100 /  5.  2.100
  libswresample   3.  2.100 /  3.  2.100
  libpostproc    55.  2.100 / 55.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/StevenLiu/Movies/objectC/facebook.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.22.102
    description     : This File is Created by Easy RealMedia Tools@!
  Duration: 02:00:27.85, start: 0.000000, bitrate: 893 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x480, 797 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 87 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Output #0, h264, to 'a.h264':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    description     : This File is Created by Easy RealMedia Tools@!
    encoder         : Lavf58.17.101
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x480, q=2-31, 797 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame=   52 fps=0.0 q=-1.0 Lsize=     210kB time=00:00:02.00 bitrate= 859.6kbits/s speed= 100x
video:210kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%



执行完成后,会生成一个a.h264,那么就看一下a.h264里面相关的信息:


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

发表于 2018-8-24 10:16:44 | 显示全部楼层
顶一个
回复

使用道具 举报

发表于 2018-8-24 16:18:03 | 显示全部楼层
大师兄,不知道您那边这样生成后的a.h264用elecard能否正常播放,我这边执行上述命令后,在原有的sei末尾追加了sei_user_data信息,但是原本视频流sei后跟的sps,pps被覆盖了。导致elecard无法正常播放。看您的码流貌似也是一样的情况
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|Archiver|ChinaFFmpeg

GMT+8, 2024-12-27 12:04 , Processed in 0.048920 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表