分享几个Linux下的码流分析工具

windows下的码流分析工具非常多,比如elecard streameye,当然还有众多开源贡献者制作的小工具,但是很多时候我们都需要在Linux下做开发,也可能需要做一些简单的码流分析工作,这里就分享几个常用的工具给大家.这些工具使用起来都很简单,不用输特别长的命令,也都有对应的windows版本.如果有朋友还了解其他工具,可以在评论中补充~

0\Mediainfo

这个就不用介绍了吧,大家都知道的码流分析工具,虽然只是一些简单的信息,但有时候基本够用了.如果你用的是ubuntu,可以直接在ubuntu软件中心下载,有图形界面.简单易用.

1\Bento4

Bento4是一套开源库,专用于mp4格式文件的读写,同时还提供一套开源工具,支持的功能非常多,列举如下

mp4info:命令行工具,显示一些high level的信息,包括tracks和codec的信息,比如像下面这样

 

File:
  major brand:      iso4
  minor version:    0
  compatible brand: iso4
  compatible brand: hvc1
  compatible brand: letv

Movie:
  duration:   152393 ms
  time scale: 90000
  fragments:  no

Found 2 Tracks
Track 1:
  flags:        1 ENABLED
  id:           1
  type:         Video
  duration: 150000 ms
  language: und
  media:
    sample count: 3750
    timescale:    90000
    duration:     13500000 (media timescale units)
    duration:     150000 (ms)
    bitrate (computed): 3516.725 Kbps
  display width:  2560.000000
  display height: 1440.000000
  frame rate (computed): 25.000
  Sample Description 0
    Bytes: 0000000000000001000000000000000000000000000000000a0005a0004800000048000000000000000100000000000000000000000000000000000000000000000000000000000000000018ffff000000766876634301008000000000000000000000f000fcfdf8f800000f03a00001001840010c01ffff01600000030080000003000003009699c090a10001002a420101016000000300800000030000030096a001402005a16599e49132b8040000030004000003006420a2000100064401c173d189
    Coding:      hvc1 (H.265)
    Width:       2560
    Height:      1440
    Depth:       24
    HEVC Profile Space:       0
    HEVC Profile:             0
    HEVC Profile Compat:      80000000
    HEVC Level:               0.0
    HEVC Tier:                0
    HEVC Chroma Format:       1 (4:2:0)
    HEVC Chroma Bit Depth:    8
    HEVC Luma Bit Depth:      8
    HEVC Average Frame Rate:  0
    HEVC Constant Frame Rate: 0
    HEVC NALU Length Size:    4
    HEVC Sequences:
      {
        Array Completeness=1
        Type=32 (VPS_NUT - Video parameter set)
        40010c01ffff01600000030080000003000003009699c090
      }
      {
        Array Completeness=1
        Type=33 (SPS_NUT - Sequence parameter set)
        420101016000000300800000030000030096a001402005a16599e49132b8040000030004000003006420
      }
      {
        Array Completeness=1
        Type=34 (PPS_NUT - Picture parameter set)
        4401c173d189
      }
    Codecs String: hvc1.0.1.L0.0
Track 2:
  flags:        3 ENABLED IN-MOVIE
  id:           2
  type:         Audio
  duration: 152392 ms
  language: eng
  media:
    sample count: 6563
    timescale:    44100
    duration:     6720512 (media timescale units)
    duration:     152393 (ms)
    bitrate (computed): 128.011 Kbps
  Sample Description 0
    Bytes: 000000000000000100000000000000000002001000000000ac440000000000276573647300000000031900000004114015000206000208c80001f40c05021210060102
    Coding:      mp4a (MPEG-4 Audio)
    Stream Type: Audio
    Object Type: MPEG-4 Audio
    Max Bitrate: 133320
    Avg Bitrate: 128012
    Buffer Size: 518
    Codecs String: mp4a.40.2
    MPEG-4 Audio Object Type: 2 (AAC Low Complexity)
    MPEG-4 Audio Decoder Config:
      Sampling Frequency: 44100
      Channels: 2
    Sample Rate: 44100
    Sample Size: 16
    Channels:    2

除此之外,mp4info还可以查看一些sample的信息,包括size\offset\duration\dts等信息,但是我更喜欢用下面的工具来查看这些信息

 

mp4dump:同样是命令行工具,可以显示完整的atom/box structure,像下面这样

 

[ftyp] size=8+20
  major_brand = iso4
  minor_version = 0
  compatible_brand = iso4
  compatible_brand = hvc1
  compatible_brand = letv
[moov] size=8+56706
  [mvhd] size=12+96
    timescale = 90000
    duration = 13715330
    duration(ms) = 152393
  [iods] size=12+12
    [InitialObjectDescriptor] size=5+7
      id = 1
      include inline profile level flag = 0
      OD profile level = ff
      scene profile level = ff
      audio profile level = f
      visual profile level = ff
      graphics profile level = ff
  [trak] size=8+26015
    [tkhd] size=12+80, flags=1
      enabled = 1
      id = 1
      duration = 13500000
      width = 2560.000000
      height = 1440.000000
    [mdia] size=8+25879
      [mdhd] size=12+20
        timescale = 90000
        duration = 13500000
        duration(ms) = 150000
        language = und
      [hdlr] size=12+21
        handler_type = vide
        handler_name = 
      [minf] size=8+25806
        [vmhd] size=12+8, flags=1
          graphics_mode = 0
          op_color = 0000,0000,0000
        [dinf] size=8+28
          [dref] size=12+16
            [url ] size=12+0, flags=1
              location = [local to file]
        [stbl] size=8+25742
          [stsd] size=12+226
            entry-count = 1
            [hvc1] size=8+214
              data_reference_index = 1
              width = 2560
              height = 1440
              compressor = 
              [hvcC] size=8+110
                Configuration Version = 1
                Profile Space = 0
                Profile = 0
                Tier = 0
                Profile Compatibility = 80000000
                Constraint = 0
                Level = 0
                Min Spatial Segmentation = 0
                Parallelism Type = 0
                Chroma Format = 1
                Chroma Depth = 8
                Luma Depth = 8
                Average Frame Rate = 0
                Constant Frame Rate = 0
                Number Of Temporal Layers = 1
                Temporal Id Nested = 1
                NALU Length Size = 4
              [colr] size=8+10
          [stts] size=12+12
            entry_count = 1
          [stsz] size=12+15008
            sample_size = 0
            sample_count = 3750
          [stsc] size=12+7072
            entry_count = 589
          [stco] size=12+3268
            entry_count = 816
          [stss] size=12+84
            entry_count = 20
    [edts] size=8+28
      [elst] size=12+16
        entry count = 1
        entry/segment duration = 13500000
        entry/media time = 7200
        entry/media rate = 1
  [trak] size=8+30430
    [tkhd] size=12+80, flags=3
      enabled = 1
      id = 2
      duration = 13715330
      width = 0.000000
      height = 0.000000
    [mdia] size=8+30308
      [mdhd] size=12+20
        timescale = 44100
        duration = 6720512
        duration(ms) = 152392
        language = eng
      [hdlr] size=12+21
        handler_type = soun
        handler_name = 
      [minf] size=8+30235
        [smhd] size=12+4
          balance = 0
        [dinf] size=8+28
          [dref] size=12+16
            [url ] size=12+0, flags=1
              location = [local to file]
        [stbl] size=8+30175
          [stsd] size=12+91
            entry-count = 1
            [mp4a] size=8+79
              data_reference_index = 1
              channel_count = 2
              sample_size = 16
              sample_rate = 44100
              [esds] size=12+39
                [ESDescriptor] size=5+34
                  es_id = 0
                  stream_priority = 0
                  [DecoderConfig] size=5+20
                    stream_type = 5
                    object_type = 64
                    up_stream = 0
                    buffer_size = 518
                    max_bitrate = 133320
                    avg_bitrate = 128012
                    DecoderSpecificInfo = 12 10 
                  [Descriptor:06] size=5+1
          [stts] size=12+12
            entry_count = 1
          [stsz] size=12+26260
            sample_size = 0
            sample_count = 6563
          [stsc] size=12+484
            entry_count = 40
          [stco] size=12+3268
            entry_count = 816
    [udta] size=8+14
      [name] size=8+6
  [udta] size=8+105
    [meta] size=12+93
      [hdlr] size=12+21
        handler_type = mdir
        handler_name = 
      [ilst] size=8+52
        [.too] size=8+44
          [data] size=8+36
            type = 1
            lang = 0
            value = HandBrake rev5474 2014101599
[mdat] size=8+68377095
[free] size=8+138248

通过设置不同的verbosity级别,还可以看到每个box的每个字段的更详细的信息.此外,还可以把某一个track的二进制内容完整的dump出来.

 

mp4edit:命令行工具,可以给一个mp4文件增加\插入\删除\替换atom/box,当然这已经不是我们要的码流分析功能了,但还是在这里写一笔吧,下面很多工具也都是跟码流分析无关的,但都是Bento4开源工具集里面的,有兴趣的朋友可以选择性的深入了解
mp4extract:命令行工具,可以将某一个atom/box的二进制数据完整的dump出来
mp4encrypt&mp4decrypt:命令行工具,分别支持对MP4文件的加密和解密
mp4fragment&mp4split:命令行工具,前者将non-fragmented的文件转为fragmented MP4,后者完成逆向的工作.fragmented MP4是一种专为流媒体传输设计的格式.
mp4tag:命令行工具,可以显示/编辑MP4的元数据
mp4mux&mp42aac&mp42avc:命令行工具,第一个工具用于将ES流mux为一个mp4文件,但是只支持AVC\HEVC\AAC,后两个工具则分别实现从mp4文件中提取aac流和avc流的功能
mp42hls:命令行工具,将MP4文件转码为HLS,自动生成切片和m3u8文件,支持AES加密
mp42ts:命令行工具,MP4转TS
mp4dash:命令行工具,将一个或多个MP4文件转码为DASH内容,支持加密
mp4dashclone:py脚本,将服务器端的DASH内容拷贝到本地creates a local clone of a remote or local MPEG DASH presentation, optionally encrypting the segments as they are cloned.不过就实际体验来看,对MPD的支持不够完善,很多都不能下载.不如直接用wget -r -np -nH -R index.html your_url下载来的方便.不过这个python代码写的真是很漂亮,值得学习.

2\ffprobe

大名鼎鼎的ffmpeg想必大家都听过,ffprobe也是其开源工具集中的一项,上面介绍的Bento4系列工具基本都是做封装格式解析的,我喜欢用ffprobe做编码格式的分析.当然,ffprobe也可以做封装格式的解析.常用的几个命令和作用如下

 

-show_data          show packets data
-show_data_hash     show packets data hash
-show_error         show probing error
-show_format        show format/container info
-show_frames        show frames info
-show_format_entry entry  show a particular entry from the format/container info
-show_entries entry_list  show a set of specified entries
-show_packets       show packets info
-show_programs      show programs info
-show_streams       show streams info
-show_chapters      show chapters info
-count_frames       count the number of frames per stream
-count_packets      count the number of packets per stream
-show_program_version  show ffprobe version
-show_library_versions  show library versions
-show_versions      show program and library versions
-show_pixel_formats  show pixel format descriptions
-show_private_data  show private data

以show_frames为例,可以输出每个帧的信息,像下面这样

 

 

[FRAME]
media_type=video
stream_index=0
key_frame=1
pkt_pts=0
pkt_pts_time=0.000000
pkt_dts=0
pkt_dts_time=0.000000
best_effort_timestamp=0
best_effort_timestamp_time=0.000000
pkt_duration=3600
pkt_duration_time=0.040000
pkt_pos=56759
pkt_size=5560
width=3840
height=2160
pix_fmt=yuv420p
sample_aspect_ratio=N/A
pict_type=I
coded_picture_number=0
display_picture_number=0
interlaced_frame=0
top_field_first=0
repeat_pict=0
[/FRAME]
[FRAME]
media_type=video
stream_index=0
key_frame=0
pkt_pts=3600
pkt_pts_time=0.040000
pkt_dts=3600
pkt_dts_time=0.040000
best_effort_timestamp=3600
best_effort_timestamp_time=0.040000
pkt_duration=3600
pkt_duration_time=0.040000
pkt_pos=71616
pkt_size=405
width=3840
height=2160
pix_fmt=yuv420p
sample_aspect_ratio=N/A
pict_type=B
coded_picture_number=3
display_picture_number=0
interlaced_frame=0
top_field_first=0
repeat_pict=0
[/FRAME]
[FRAME]
media_type=audio
stream_index=1
key_frame=1
pkt_pts=1024
pkt_pts_time=0.023220
pkt_dts=1024
pkt_dts_time=0.023220
best_effort_timestamp=1024
best_effort_timestamp_time=0.023220
pkt_duration=1024
pkt_duration_time=0.023220
pkt_pos=72047
pkt_size=9
sample_fmt=fltp
nb_samples=1024
channels=2
channel_layout=stereo
[/FRAME]

如果你用过streameye,一定记得它那个经典的图形界面,可以显示每个帧的大小和类型,可以看到,这里ffprobe完全能够完成一样的工作.

 

3\FLVmeta

本来是一个编辑flv文件的metadata的工具,有些flv文件上传之后不能seek,就是因为metadata有问题,这时候就可以用到FLVmeta,但其实它也可以用来做flv文件的码流分析,输出每个tag的信息,像下面这样

 



  
    
      
        
          
        
        
          
        
        
          
        
        
          
        
        
          
        
        
          
        
        
          iso5
        
        
          1
        
        
          avc1iso5dsmsmsixdash
        
        
          Lavf57.41.100
        
        
          
        
      
    
  
  
    
  
  
    
  
  
    
  
  
    
  
  
    
  
  
    
  
  
    
  
  
    
  
  
    
  

 

5 \ tsinfo

用于查看ts码流信息的工具.在ubuntu下sudo apt-get install tstools安装tsinfo工具,即可用它查看ts码流信息

 

关注公众号,掌握更多多媒体领域知识与资讯

文章帮到你了?可以扫描如下二维码进行打赏~,打赏多少您随意~

 

 

 

你可能感兴趣的:(基础知识)