5

I'm trying to extract information about the frame types in TS packets. Using FFMEPG I'm sending MPEG TS encapsulated video (compressed with x264), and on the other side I'm recording the received packets with Wireshark. My packets are 188 bytes long, which corresponds to one MPEG TS packet. Now I need to find out which TS packets carry I, P, or B frame data.

I tried to detect Picture Header in my data (00 00 01 00), based on this post: http://forum.digital-digest.com/f4/help-extract-i-frames-mpeg2-ts-89736.html but I couldn't find it. All I can register is the start of PES packet (00 00 00 01 E0). I'm totaly confused about the formats. Which part of PES says which frame type one TS packet transmits?

Thank you.

stani
  • 111
  • 1
  • 1
  • 7
  • Were you able to use ffprobe to do this? – av501 Aug 29 '12 at 09:42
  • It's not trivial to detect frame start code in a ts-packet. First of all the start code emulation might occur (e.g. in private data section of PES header). Moreover, the start code can be broken between two ts-packets, for example '00 00' is the end of the first ts-packet and '01' is the start of ts-packet data. – Shevach Riabtsev Dec 18 '17 at 10:24
  • 1
    You could try using: https://github.com/tsduck/tsduck – Pierz Jul 30 '20 at 10:17

1 Answers1

9

Just capture all your content in ts form and run ffprobe over it.

ffprobe -show_frames and look for pict_type in the video frames. Write a small script to parse the output and give you the output. If you are too lazy to do that

ffprobe -show_frames | grep pict_type | grep -n I
should give you frame numbers directly.

will work for any format as long as it is a valid video file.

av501
  • 6,645
  • 2
  • 23
  • 34
  • forgot to mention ffprobe is part of ffmpeg utility – av501 Aug 26 '12 at 17:02
  • Thank you so much for your answer. I've tried to use the ffprobe as you suggested (using -show_frames option), but it gives me the information per each frame, and I need the information about which frame type data is stored in each packet. Using -show_packet option does not provide either wheter the data in the packet are of frame type I, P, or B. – stani Aug 29 '12 at 15:01
  • 1
    You can correlate packets to the frames. Write a small script to do that for you! Also being a transport stream each packet will be 188 bytes. So from ffprobe you can get the frame size for each frame. you now have a way of correlating the two directly because you know the size of each frame and packets size is 188. Remember packets get padded out to 188 bytes when there is no frame data [frame ends before end of packet] so new frames start on new packets. – av501 Aug 29 '12 at 15:05
  • I also tried to use the MPEG2-TS Packet analyser 2.4.1.2 (from www.pjdaniel.org.uk/mpeg/), and it would read PES header, but it cannot find the picture header -- it gives: "Video sequence Sequence header code not found in this packet AFD not found in this packet". How then the decoder (or ffprobe) knows what frame type data each packet contains? – stani Aug 29 '12 at 15:08
  • I see. It seems as a hard way t do it, but it's doable. I wanted to do it by reading a packet by packet because later I wanted to experiment with the cases when I intentionally drop some of the packets and see the effect of dropping the packets to the video quality. Thank you. – stani Aug 29 '12 at 15:12