5

Is there any good linux/unix tool to get the properties of an H264 .TS file?

I need the duration, video resolution and bitrate, fps, audio resolution and bitrate.

I tried mplayer -vo null -ao null -frames 0 -identify _file_, but it reports wrong video width and height, and also reports the file length (duration) as 0.00.

Charles
  • 50,943
  • 13
  • 104
  • 142
Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176

3 Answers3

11

You can run mediainfo (here) and parse its output.

mediainfo <filename> will give you this kind of information:

General
ID                                       : 2 (0x2)
Format                                   : MPEG-TS
File size                                : 915 MiB
Duration                                 : 8mn 31s
Start time                               : UTC 2009-06-09 14:15:57
End time                                 : UTC 2009-06-09 14:24:12
Overall bit rate                         : 15.0 Mbps

Video #1
ID                                       : 256 (0x100)
Menu ID                                  : 1 (0x1)
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : Main@L3.0
Format settings, CABAC                   : Yes
Format settings, ReFrames                : 4 frames
Codec ID                                 : 27
Duration                                 : 8mn 31s
Width                                    : 720 pixels
Height                                   : 576 pixels
Display aspect ratio                     : 4:3
Frame rate                               : 25.000 fps
Standard                                 : PAL
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : MBAFF
Scan order                               : Top Field First
Color primaries                          : BT.470-6 System B, BT.470-6 System G, BT.601-6 625, BT.1358 625, BT.1700 625 PAL, BT.1700 625 SECAM
Transfer characteristics                 : BT.470-6 System B, BT.470-6 System G
Matrix coefficients                      : BT.470-6 System B, BT.470-6 System G, BT.601-6 625, BT.1358 625, BT.1700 625 PAL, BT.1700 625 SECAM, IEC 61966-2-4 601

Video #2
ID                                       : 1001 (0x3E9)
Menu ID                                  : 3 (0x3)
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : Main@L3.0
Format settings, CABAC                   : Yes
Format settings, ReFrames                : 4 frames
Format settings, GOP                     : M=3, N=24
Codec ID                                 : 27
Duration                                 : 8mn 30s
Width                                    : 720 pixels
Height                                   : 576 pixels
Display aspect ratio                     : 4:3
Frame rate                               : 25.000 fps
Standard                                 : PAL
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : MBAFF
Color primaries                          : BT.470-6 System B, BT.470-6 System G, BT.601-6 625, BT.1358 625, BT.1700 625 PAL, BT.1700 625 SECAM
Transfer characteristics                 : BT.470-6 System B, BT.470-6 System G
Matrix coefficients                      : BT.470-6 System B, BT.470-6 System G, BT.601-6 625, BT.1358 625, BT.1700 625 PAL, BT.1700 625 SECAM, IEC 61966-2-4 601

Audio #1
ID                                       : 258 (0x102)
Menu ID                                  : 1 (0x1)
Format                                   : MPEG Audio
Format version                           : Version 1
Format profile                           : Layer 2
Mode                                     : Joint stereo
Mode extension                           : Intensity Stereo + MS Stereo
Codec ID                                 : 3
Duration                                 : 8mn 31s
Bit rate mode                            : Constant
Bit rate                                 : 192 Kbps
Channel(s)                               : 2 channels
Sampling rate                            : 48.0 KHz
Compression mode                         : Lossy
Stream size                              : 11.7 MiB (1%)

Audio #2
ID                                       : 1002 (0x3EA)
Menu ID                                  : 3 (0x3)
Format                                   : MPEG Audio
Format version                           : Version 1
Format profile                           : Layer 2
Codec ID                                 : 3
Duration                                 : 8mn 31s
Bit rate mode                            : Constant
Bit rate                                 : 192 Kbps
Channel(s)                               : 2 channels
Sampling rate                            : 48.0 KHz
Compression mode                         : Lossy
Delay relative to video                  : 7s 978ms
Stream size                              : 11.7 MiB (1%)

Menu #1
ID                                       : 257 (0x101)
Menu ID                                  : 1 (0x1)
Duration                                 : 8mn 31s
List                                     : 256 (0x100) (AVC) / 258 (0x102) (MPEG Audio)
Service name                             : vv
Service type                             : digital television

Menu #2
ID                                       : 1000 (0x3E8)
Menu ID                                  : 3 (0x3)
Duration                                 : 8mn 31s
List                                     : 1001 (0x3E9) (AVC) / 1002 (0x3EA) (MPEG Audio)
Service name                             : Lenni
Service type                             : digital television
Cyrille
  • 13,905
  • 2
  • 22
  • 41
1

You should be able to use ffmpeg to get good details of the encoded video. VLC will also give you quite a bit of information but may not all the information you need. You can check for that as well. If you need even more information, then you can extract the video and audio elementary streams from the TS file ( using bbdemux etc utilities ) and then you can analyse the video stream separately using Elecard Stream analyzer.

Vibgyor

Mukesh
  • 242
  • 1
  • 7
  • 1) have you tried *any* of these to get the duration of a .ts file? 2) can you use VLC to *programmatically* get the info? – Karoly Horvath Feb 15 '12 at 15:17
  • Hi, Transport stream (TS ) is a streaming format unlike avi,mp4 etc which are file formats. In TS, there is no identifier that can tell you the duration of the stream. But probably, by using the time stamps of the first video packets and the last one,you may get the duration of the stream. Am not sure whether you can use VLC programmaticaly to get this info but you can try FFMPEG. - VIbgyor – Mukesh Feb 16 '12 at 05:32
  • thanks, ffmpeg at least shows the duration. unfortunately not the (a&v) stream bitrates. – Karoly Horvath Feb 24 '12 at 11:17
  • That's good! Did you use FFMPEG programatically or in offline mode? If in offline mode, what is the FFMPEG command that you used for it? – Mukesh Feb 24 '12 at 12:00
  • there is a separate utility called `ffprobe`. – Karoly Horvath Feb 24 '12 at 13:12
1

For TS audio and video bitrate I wrote a small utility.

It searches for PAT packet, then extracts PMT PID, then looks up the PMT packet and extracts the PID for video and audio packets. AFter that I'm able to calculate the relative proportion of audio and video packets in the whole stream.

From the total bitrate (obtained with other utilities (eg: size/duration)) then it's a simple multiplication to get the values..

Note: I don't analyze the whole stream, only the first couple of megabytes.

I'm still interested in any existing utilities which can give me this info.

Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176