Opened 11 years ago

Last modified 9 years ago

#2547 open defect

-muxrate option doesn't work with stream_segment mpegts output

Reported by: Jason Livingston Owned by:
Priority: normal Component: avformat
Version: git-master Keywords: segment
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

When I use the -muxrate parameter with the mpegts muxer directly, it works fine without any errors and I get the desired muxrate. But it is not working when using the mpegts muxer indirectly via the stream_segment muxer (even after patching segment.c to pass the muxrate parameter to the mpegts muxer and verifying that the right value was passed - see below).

Using mpegts muxer directly:
ffmpeg -i lg4test.ts -map 0:0 -vcodec libx264 -s 640x360 -b:v 1M -minrate 1M -maxrate 1M -bufsize 500K -muxrate 1.25M -g 60 -profile:v main -map 0:1 -acodec aac -strict experimental -b:a 128K -ac 2 -ar 48000 -f mpegts -v verbose test.ts

Complete console output attached as: mpegts_output.txt

Quote from the output:
[mpegts @ 0x7fc381829c00] muxrate 1250000, pcr every 16 pkts, sdt every 415, pat/pmt every 83 pkts

So, that looks good. Next I want to do the same thing when using mpegts via the stream_segment muxer.

First I edited libavformat/segment.c to enable the muxrate option to be passed to the muxer specified by -segment_format, via a new option called -segment_format_muxrate (see patch attached). There may be a better way to accomplish this, but it works for now. If you prefer, I can submit this patch first to ffmpeg-devel and then inquire about this bug.

Next, making use of this new option:

ffmpeg -i lg4test.ts -map 0:0 -vcodec libx264 -s 640x360 -b:v 1M -minrate 1M -maxrate 1M -bufsize 500K -muxrate 1.25M -g 60 -profile:v main -map 0:1 -acodec aac -strict experimental -b:a 128K -ac 2 -ar 48000 -f ssegment -segment_list test.m3u8 -segment_list_flags +live -segment_time 10 -segment_format mpegts -segment_format_muxrate 1.25M -segment_time_delta 1.0 -v verbose test%05d.ts

Complete console output attached as: ssegment_output.txt

This message cofirms that the muxrate option was correctly passed to the mpegts muxer:
[mpegts @ 0x7fdff3c16800] muxrate 1250000, pcr every 16 pkts, sdt every 415, pat/pmt every 83 pkts

However, as you can see in the console output, I now get this error message repeated very often:
[mpegts @ 0x7fdff3c16800] dts < pcr, TS is invalid

Last message repeated 58 times


When this error occurs, I found that the size of each segment file (which should be all roughly the same size, since they are all approx. the same duration) is actually growing by multiples, e.g.:
ls -al test0*.ts
-rw-r--r-- 1 jasonlivingston admin 1657784 May 8 22:39 test00000.ts
-rw-r--r-- 1 jasonlivingston admin 3273268 May 8 22:39 test00001.ts
-rw-r--r-- 1 jasonlivingston admin 5023736 May 8 22:39 test00002.ts
-rw-r--r-- 1 jasonlivingston admin 6452160 May 8 22:39 test00003.ts
-rw-r--r-- 1 jasonlivingston admin 8077796 May 8 22:39 test00004.ts
-rw-r--r-- 1 jasonlivingston admin 9741784 May 8 22:39 test00005.ts
-rw-r--r-- 1 jasonlivingston admin 11516692 May 8 22:39 test00006.ts
-rw-r--r-- 1 jasonlivingston admin 13087244 May 8 22:39 test00007.ts
-rw-r--r-- 1 jasonlivingston admin 14500816 May 8 22:39 test00008.ts
-rw-r--r-- 1 jasonlivingston admin 16241884 May 8 22:39 test00009.ts

Again, these are all the same duration and same CBR, so they should be roughly the same size.

Any ideas why this works fine for using mpegts directly, but not when using mpegts via ssegment?

Attachments (4)

0001-libavformat-segment.c-add-muxrate-option-for-segment.patch (2.9 KB ) - added by Jason Livingston 11 years ago.
patch needed to pass muxrate option to stream_segment muxer
mpegts_output.txt (7.1 KB ) - added by Jason Livingston 11 years ago.
ffmpeg console output when using mpegts muxer directly
ssegment_output.txt (11.6 KB ) - added by Jason Livingston 11 years ago.
ffmpeg console output using stream_segment muxer
ssegment_mpeg2video.txt (8.0 KB ) - added by Jason Livingston 11 years ago.
console output using mpeg2video and mp2 instead of libx264 and aac

Download all attachments as: .zip

Change History (14)

by Jason Livingston, 11 years ago

patch needed to pass muxrate option to stream_segment muxer

by Jason Livingston, 11 years ago

Attachment: mpegts_output.txt added

ffmpeg console output when using mpegts muxer directly

by Jason Livingston, 11 years ago

Attachment: ssegment_output.txt added

ffmpeg console output using stream_segment muxer

comment:1 by Carl Eugen Hoyos, 11 years ago

Do you think this is a regression (did it work with older versions of FFmpeg)?

comment:2 by Carl Eugen Hoyos, 11 years ago

And is the problem only reproducible using an external library (libx264) or also if you use a native encoder?

in reply to:  2 comment:3 by Jason Livingston, 11 years ago

Replying to cehoyos:

And is the problem only reproducible using an external library (libx264) or also if you use a native encoder?

Hi Carl,
Same exact problem using mpeg2video instead of libx264, or mp2 audio instead of aac (or both). Attached new console output using mpeg2video and mp2.

I've been having the same problem for a long time and thought it was something in my code, so if it is a regression, it's not something recent.

by Jason Livingston, 11 years ago

Attachment: ssegment_mpeg2video.txt added

console output using mpeg2video and mp2 instead of libx264 and aac

comment:4 by Carl Eugen Hoyos, 11 years ago

Keywords: segment added
Priority: importantnormal

comment:5 by Jason Livingston, 11 years ago

Would it be ok to post this patch as a RFC to ffmpeg-devel and refer to this ticket? I believe the patch itself is working ok... it just exposes a bug elsewhere. Thanks.

in reply to:  5 comment:6 by Carl Eugen Hoyos, 11 years ago

Replying to jettoblack:

Would it be ok to post this patch as a RFC to ffmpeg-devel and refer to this ticket?

Why not?

comment:7 by Michael Niedermayer, 11 years ago

Please see child_next/child_class_next to expose "sub" muxer options to the parent muxer

comment:8 by Zach, 9 years ago

I am having the same DTS < PCR error with this command.

ffmpeg -v 9 -loglevel 99 -rtbufsize 1500M -f dshow -i video="AmaRec Video Capture" -f dshow -i audio="AmaRec Audio Capture" -f mpegts -mpegts_pmt_start_pid 0x256 -mpegts_start_pid 0x300 -vf "fps=29.97,scale=704x480" -muxrate 1000k -vcodec mpeg2video -threads 0 -crf 0 -tune zerolatency -pix_fmt yuv420p -b:v 500k -acodec ac3 -ar 48000 -b:a 50k -me_method epzs  udp://239.0.0.230:1234?pkt_size=188

Is this likely the same stream_segment issue, or something else? I only get the error when using the -muxrate command. If it is related, I can provide more info and try to help with code. If you think it is unrelated I can make a different ticket and debug on my own.

Edit: I my problem encounters the same issue from a different direction as i am not using stream segment directly, although since the mpegts is packetised, it very well may use the same code.

Last edited 9 years ago by Zach (previous) (diff)

in reply to:  8 comment:9 by Carl Eugen Hoyos, 9 years ago

Replying to zcybercomputing:

I am having the same DTS < PCR error with this command.

ffmpeg -v 9 -loglevel 99 -rtbufsize 1500M -f dshow -i video="AmaRec Video Capture" -f dshow -i audio="AmaRec Audio Capture" -f mpegts -mpegts_pmt_start_pid 0x256 -mpegts_start_pid 0x300 -vf "fps=29.97,scale=704x480" -muxrate 1000k -vcodec mpeg2video -threads 0 -crf 0 -tune zerolatency -pix_fmt yuv420p -b:v 500k -acodec ac3 -ar 48000 -b:a 50k -me_method epzs  udp://239.0.0.230:1234?pkt_size=188

This ticket is not reproducible with -f mpegts, please consider posting on the user mailing list.

comment:10 by Carl Eugen Hoyos, 9 years ago

Reproduced by developer: set
Status: newopen

Reproducible with the following command, -muxrate has no effect:

$ ffmpeg -f lavfi -i testsrc -map 0 -muxrate 2M -f ssegment -segment_time 10 -t 30 out%d.ts
ffmpeg version N-67845-g0f8908a Copyright (c) 2000-2014 the FFmpeg developers
  built on Nov 20 2014 15:18:45 with gcc 4.7 (SUSE Linux)
  configuration: --enable-gpl
  libavutil      54. 14.100 / 54. 14.100
  libavcodec     56. 12.101 / 56. 12.101
  libavformat    56. 14.100 / 56. 14.100
  libavdevice    56.  3.100 / 56.  3.100
  libavfilter     5.  2.103 /  5.  2.103
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, lavfi, from 'testsrc':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 320x240 [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
Output #0, stream_segment,ssegment, to 'out%d.ts':
  Metadata:
    encoder         : Lavf56.14.100
    Stream #0:0: Video: mpeg2video, yuv420p, 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 90k tbn, 25 tbc
    Metadata:
      encoder         : Lavc56.12.101 mpeg2video
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> mpeg2video (native))
Press [q] to stop, [?] for help
frame=  750 fps=0.0 q=8.4 Lsize=N/A time=00:00:29.96 bitrate=N/A
video:1018kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Note: See TracTickets for help on using tickets.