[FFmpeg-devel] [PATCH] MPEG-TS/-PS : better probing for duration and start-time for all streams in a container
Gaullier Nicolas
nicolas.gaullier at arkena.com
Wed May 14 12:03:51 CEST 2014
Hello,
To reproduce all the problems, I have generated a small single sample file (13Mo) from free to use content (bigbuckbunny->ffmbc cbr 30Mbps open gop transcode->ffmpeg trim-rewrap). It is not ideal because the starting of the file is a little bit "crude" : the two first B frames lack their P reference and an audio header missing is reported, but anyway it plays, and I can assure you that what is observed is exactly the same as real-life content strictly conformant to the standards. If needed, I could also with some more effort try to put this content on a production encoder to give you perfect sample files (but I cannot send you my everyday files because they are copyrighted). I am a newbie here, please tell me where I can send you this file.
Here is the analysis of this sample file:
1a SEQUENCE MPEG2 MP at HL 1920x1088 chroma 960x544 fps 24 maxBps 3750000 vbv 1222656 picture 1920x1080 display 1920x1080 pixel 1x1
22 GOP 0: 0: 1:10
33 PICTURE I fields 2 TFF pts 00015450 dts 0001285e time_ref 2 offset 0/0 0/0
2625e SLICE
26270 PICTURE B fields 2 TFF pts 00013704 dts 00013704 time_ref 0 offset 0/0 0/0
(...)
c845aa GOP 0: 0: 4:22
c845bb PICTURE I fields 2 TFF pts 00061422 dts 0005f6d6 time_ref 1 offset 0/0 0/0
cc5249 SLICE
cc525b PICTURE B fields 2 TFF pts 0006057c dts 0006057c time_ref 0 offset 0/0 0/0
And here below is the git diff of the ffprobe output with -show_streams -show_format -print_format xml.
You can see that :
- "duration" is missing/not set in the stream 0 (mp2) whereas it is set with the patched ffprobe
- "start time" of the video track is 2 frames earlier with the patched ffprobe and is actually 79620=hex2dec(00013704) as analysed above
- "duration" of the video track is 4 frames more in the patched ffprobe : 2 frames from the start time and 2 frames from the end of the file ; as analysed above, the duration reported by the patched version is correct : 00:00:03:14 is 3.5833..s @24fps as expected
- "format" start time/durations are altered accordingly
Sorry about the bad formatting of my patch, I am not a highly skilled developer, I am not used to open source methods, and I do not have a standard linux dev environment set yet, but I promise I will improve next time!
Nicolas Gaullier
-----
diff --git a/git.xml b/patch.xml
index 876f4dd..93dd843 100644
--- a/git.xml
+++ b/patch.xml
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<ffprobe>
<streams>
- <stream index="0" codec_name="mp2" codec_long_name="MP2 (MPEG audio layer 2)" codec_type="audio" codec_time_base="1/48000" codec_tag_string="[0][0][0][0]" codec_tag="0x0000" sample_fmt="s16p" sample_rate="48000" channels="2" channel_layout="stereo" bits_per_sample="0" id="0x1c0" r_frame_rate="0/0" avg_frame_rate="0/0" time_base="1/90000" start_pts="45000" start_time="0.500000" bit_rate="64000">
+ <stream index="0" codec_name="mp2" codec_long_name="MP2 (MPEG audio layer 2)" codec_type="audio" codec_time_base="1/48000" codec_tag_string="[0][0][0][0]" codec_tag="0x0000" sample_fmt="s16p" sample_rate="48000" channels="2" channel_layout="stereo" bits_per_sample="0" id="0x1c0" r_frame_rate="0/0" avg_frame_rate="0/0" time_base="1/90000" start_pts="45000" start_time="0.500000" duration_ts="360720" duration="4.008000" bit_rate="64000">
<disposition default="0" dub="0" original="0" comment="0" lyrics="0" karaoke="0" forced="0" hearing_impaired="0" visual_impaired="0" clean_effects="0" attached_pic="0"/>
</stream>
- <stream index="1" codec_name="mpeg2video" codec_long_name="MPEG-2 video" profile="Main" codec_type="video" codec_time_base="1/48" codec_tag_string="[0][0][0][0]" codec_tag="0x0000" width="1920" height="1080" has_b_frames="1" sample_aspect_ratio="1:1" display_aspect_ratio="16:9" pix_fmt="yuv420p" level="4" timecode="00:00:01:10" id="0x1e0" r_frame_rate="24/1" avg_frame_rate="24/1" time_base="1/90000" start_pts="87120" start_time="0.968000" duration_ts="307500" duration="3.416667">
+ <stream index="1" codec_name="mpeg2video" codec_long_name="MPEG-2 video" profile="Main" codec_type="video" codec_time_base="1/48" codec_tag_string="[0][0][0][0]" codec_tag="0x0000" width="1920" height="1080" has_b_frames="1" sample_aspect_ratio="1:1" display_aspect_ratio="16:9" pix_fmt="yuv420p" level="4" timecode="00:00:01:10" id="0x1e0" r_frame_rate="24/1" avg_frame_rate="24/1" time_base="1/90000" start_pts="79620" start_time="0.884667" duration_ts="322500" duration="3.583333">
<disposition default="0" dub="0" original="0" comment="0" lyrics="0" karaoke="0" forced="0" hearing_impaired="0" visual_impaired="0" clean_effects="0" attached_pic="0"/>
</stream>
</streams>
- <format filename="ffprobesample.mpg" nb_streams="2" nb_programs="0" format_name="mpeg" format_long_name="MPEG-PS (MPEG-2 Program Stream)" start_time="0.500000" duration="3.884667" size="13639680" bit_rate="28089264" probe_score="52"/>
+ <format filename="ffprobesample.mpg" nb_streams="2" nb_programs="0" format_name="mpeg" format_long_name="MPEG-PS (MPEG-2 Program Stream)" start_time="0.500000" duration="4.008000" size="13639680" bit_rate="27224910" probe_score="52"/>
</ffprobe>
-----Message d'origine-----
De : Michael Niedermayer [mailto:michaelni at gmx.at]
Envoyé : mardi 13 mai 2014 18:59
À : FFmpeg development discussions and patches; Gaullier Nicolas
Objet : Re: [FFmpeg-devel] [PATCH] MPEG-TS/-PS : better probing for duration and start-time for all streams in a container
On Tue, May 13, 2014 at 08:00:21AM +0000, Gaullier Nicolas wrote:
> [Sorry, I think you prefer patch in plain text in the body rather than
> attached in (I suppose) binary form. Here below]
>
> Hello,
> In the MPEG2TS/PS containers, FFMPEG/FFPROBE does not report accurate duration and start time:
> 1- the duration does not take into account the duration of the last
> frame
> 2- the start time is taken from the first frame, but the lowest PTS is
> often found a bit later (commonly found on broadcast open GOP
> structures with the first frame not being a key frame)
> 3- depending on the file structure, one or several audio/video streams may have no information at all (the current implementation is focused on getting one single stream info; more stream info is 'welcome' but not required), The typical use case is where the video/audio delay is very high and the bitrate high too : the end of the file contains only audio frames and the current implementation does not try to 'look further' to get the video ptses.
>
> Please review my patch - and be clement, I am not a developer and I only have a basic windows/mingw environment for testing with no FATE etc.
how can the problems this patch fixes be reproduced ?
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
I do not agree with what you have to say, but I'll defend to the death your right to say it. -- Voltaire
More information about the ffmpeg-devel
mailing list