#7693 closed defect (invalid)
ffmpeg down-samples PCR on codec copy
Reported by: | gstair | Owned by: | |
---|---|---|---|
Priority: | normal | Component: | undetermined |
Version: | unspecified | Keywords: | |
Cc: | Blocked By: | ||
Blocking: | Reproduced by developer: | no | |
Analyzed by developer: | no |
Description
When copying an MPEG2-TS video to a new file, specifying the codec option to "copy" down-samples the program clock reference (PCR) rate in the MPEG2 container relative to the original PCR. The original video has a PCR every ~100-ms and the output file has a PCR every ~1100-ms*. In the log, it states "muxrate VBR, pcr every 9000 pkts". The expected behavior would be if there is no transcoding, the file would be copied directly and not have a different PCR rate than the original file. This happens to all MPEG2-TS files and all rebroadcasting methods (UDP, RTSP, file-direct)
*Using python to read the MPEG2-TS Headers and output the PCR to show change in PCR.
How to reproduce:
%ffmpeg started on 2019-01-22 at 10:56:02 Report written to "ffmpeg-20190122-105602.log" Command line: "C:\\ffmpeg\\bin\\ffmpeg.exe" -report -v 9 -loglevel 99 -i ".\\Original_100ms_PCR.ts" -map 0 -f mpegts -c: copy ReBroadcasted_1100ms_PCR.ts ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers built with gcc 7.3.1 (GCC) 20180722 configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth libavutil 56. 14.100 / 56. 14.100 libavcodec 58. 18.100 / 58. 18.100 libavformat 58. 12.100 / 58. 12.100 libavdevice 58. 3.100 / 58. 3.100 libavfilter 7. 16.100 / 7. 16.100 libswscale 5. 1.100 / 5. 1.100 libswresample 3. 1.100 / 3. 1.100 libpostproc 55. 1.100 / 55. 1.100 Splitting the commandline. Reading option '-report' ... matched as option 'report' (generate a report) with argument '1'. Reading option '-v' ... matched as option 'v' (set logging level) with argument '9'. Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument '99'. Reading option '-i' ... matched as input url with argument '.\Original_100ms_PCR.ts'. Reading option '-map' ... matched as option 'map' (set input stream mapping) with argument '0'. Reading option '-f' ... matched as option 'f' (force format) with argument 'mpegts'. Reading option '-c:' ... matched as option 'c' (codec name) with argument 'copy'. Reading option 'ReBroadcasted_1100ms_PCR.ts' ... matched as output url. Finished splitting the commandline. Parsing a group of options: global . Applying option report (generate a report) with argument 1. Applying option v (set logging level) with argument 9. Applying option loglevel (set logging level) with argument 99. Successfully parsed a group of options. Parsing a group of options: input url .\Original_100ms_PCR.ts. Successfully parsed a group of options. Opening an input file: .\Original_100ms_PCR.ts. [NULL @ 000001663f58be80] Opening '.\Original_100ms_PCR.ts' for reading [file @ 000001663f58d000] Setting default whitelist 'file,crypto' [mpegts @ 000001663f58be80] Format mpegts probed with size=2048 and score=50 [mpegts @ 000001663f58be80] stream=0 stream_type=1b pid=100 prog_reg_desc= [mpegts @ 000001663f58be80] stream=1 stream_type=6 pid=101 prog_reg_desc= [mpegts @ 000001663f58be80] Before avformat_find_stream_info() pos: 0 bytes read:32768 seeks:0 nb_streams:2 [mpegts @ 000001663f58be80] parser not found for codec klv, packets or times may be invalid. [mpegts @ 000001663f58be80] parser not found for codec klv, packets or times may be invalid. [AVBSFContext @ 000001663fa1d3c0] nal_unit_type: 9, nal_ref_idc: 0 [AVBSFContext @ 000001663fa1d3c0] nal_unit_type: 7, nal_ref_idc: 3 [AVBSFContext @ 000001663fa1d3c0] nal_unit_type: 8, nal_ref_idc: 3 [AVBSFContext @ 000001663fa1d3c0] nal_unit_type: 6, nal_ref_idc: 0 [AVBSFContext @ 000001663fa1d3c0] nal_unit_type: 5, nal_ref_idc: 3 [h264 @ 000001663f58db40] nal_unit_type: 9, nal_ref_idc: 0 [h264 @ 000001663f58db40] nal_unit_type: 7, nal_ref_idc: 3 [h264 @ 000001663f58db40] nal_unit_type: 8, nal_ref_idc: 3 [h264 @ 000001663f58db40] nal_unit_type: 6, nal_ref_idc: 0 [h264 @ 000001663f58db40] nal_unit_type: 5, nal_ref_idc: 3 [h264 @ 000001663f58db40] Format yuv420p chosen by get_format(). [h264 @ 000001663f58db40] Reinit context to 1920x1088, pix_fmt: yuv420p [h264 @ 000001663f58db40] nal_unit_type: 9, nal_ref_idc: 0 [h264 @ 000001663f58db40] nal_unit_type: 1, nal_ref_idc: 3 [h264 @ 000001663f58db40] nal_unit_type: 9, nal_ref_idc: 0 [h264 @ 000001663f58db40] nal_unit_type: 1, nal_ref_idc: 3 [h264 @ 000001663f58db40] nal_unit_type: 9, nal_ref_idc: 0 [h264 @ 000001663f58db40] nal_unit_type: 1, nal_ref_idc: 3 [h264 @ 000001663f58db40] nal_unit_type: 9, nal_ref_idc: 0 [h264 @ 000001663f58db40] nal_unit_type: 1, nal_ref_idc: 3 [h264 @ 000001663f58db40] nal_unit_type: 9, nal_ref_idc: 0 [h264 @ 000001663f58db40] nal_unit_type: 1, nal_ref_idc: 3 [h264 @ 000001663f58db40] nal_unit_type: 9, nal_ref_idc: 0 [h264 @ 000001663f58db40] nal_unit_type: 1, nal_ref_idc: 3 [mpegts @ 000001663f58be80] Probe buffer size limit of 5000000 bytes reached [mpegts @ 000001663f58be80] After avformat_find_stream_info() pos: 0 bytes read:5787792 seeks:2 frames:188 Input #0, mpegts, from '.\Original_100ms_PCR.ts': Duration: 00:00:07.52, start: 2.000000, bitrate: 9424 kb/s Program 1 Metadata: service_name : Service01 service_provider: FFmpeg Stream #0:0[0x100], 94, 1/90000: Video: h264 (Constrained Baseline), 1 reference frame ([27][0][0][0] / 0x001B), yuv420p(progressive, left), 1920x1080 (1920x1088), 0/1, 90k tbr, 90k tbn, 180k tbc Stream #0:1[0x101], 94, 1/90000: Data: klv (KLVA / 0x41564C4B), 0/1 Successfully opened the file. Parsing a group of options: output url ReBroadcasted_1100ms_PCR.ts. Applying option map (set input stream mapping) with argument 0. Applying option f (force format) with argument mpegts. Applying option c: (codec name) with argument copy. Successfully parsed a group of options. Opening an output file: ReBroadcasted_1100ms_PCR.ts. [file @ 000001663f58fd40] Setting default whitelist 'file,crypto' Successfully opened the file. [mpegts @ 00000166406fe400] muxrate VBR, pcr every 9000 pkts, sdt every 200, pat/pmt every 40 pkts Output #0, mpegts, to 'ReBroadcasted_1100ms_PCR.ts': Metadata: encoder : Lavf58.12.100 Stream #0:0, 0, 1/90000: Video: h264 (Constrained Baseline), 1 reference frame ([27][0][0][0] / 0x001B), yuv420p(progressive, left), 1920x1080 (0x0), 0/1, q=2-31, 90k tbr, 90k tbn, 90k tbc Stream #0:1, 0, 1/90000: Data: klv (KLVA / 0x41564C4B), 0/1 Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (copy) Press [q] to stop, [?] for help cur_dts is invalid (this is harmless if it occurs once at the start per stream) cur_dts is invalid (this is harmless if it occurs once at the start per stream) cur_dts is invalid (this is harmless if it occurs once at the start per stream) [NULL @ 000001663f58db40] nal_unit_type: 7, nal_ref_idc: 3 [NULL @ 000001663f58db40] nal_unit_type: 8, nal_ref_idc: 3 cur_dts is invalid (this is harmless if it occurs once at the start per stream) frame= 9 fps=0.0 q=-1.0 size= 256kB time=00:00:00.47 bitrate=4396.4kbits/s speed=0.93x frame= 23 fps= 22 q=-1.0 size= 1280kB time=00:00:01.14 bitrate=9125.9kbits/s speed=1.11x frame= 35 fps= 23 q=-1.0 size= 1792kB time=00:00:01.70 bitrate=8610.0kbits/s speed=1.11x frame= 47 fps= 23 q=-1.0 size= 2560kB time=00:00:02.28 bitrate=9173.8kbits/s speed= 1.1x frame= 81 fps= 31 q=-1.0 size= 4352kB time=00:00:03.90 bitrate=9132.0kbits/s speed=1.52x frame= 144 fps= 47 q=-1.0 size= 7936kB time=00:00:07.00 bitrate=9280.8kbits/s speed=2.27x No more output streams to write to, finishing. frame= 152 fps= 48 q=-1.0 Lsize= 8654kB time=00:00:07.52 bitrate=9425.3kbits/s speed=2.38x video:7955kB audio:0kB subtitle:0kB other streams:46kB global headers:0kB muxing overhead: 8.159910% Input file #0 (.\Original_100ms_PCR.ts): Input stream #0:0 (video): 152 packets read (8146304 bytes); Input stream #0:1 (data): 158 packets read (47242 bytes); Total: 310 packets (8193546 bytes) demuxed Output file #0 (ReBroadcasted_1100ms_PCR.ts): Output stream #0:0 (video): 152 packets muxed (8146304 bytes); Output stream #0:1 (data): 158 packets muxed (47242 bytes); Total: 310 packets (8193546 bytes) muxed 0 frames successfully decoded, 0 decoding errors [AVIOContext @ 0000016640587b00] Statistics: 0 seeks, 34 writeouts [AVIOContext @ 000001663f595280] Statistics: 14649376 bytes read, 2 seeks
Change History (9)
comment:1 by , 6 years ago
comment:2 by , 6 years ago
Trying to set the rate with -pcr_period does not seem to work. Is there something else that needs to be specified? Also, I should probably note that if the stream is re-encoded the PCR is set correctly, but re-encoding is not an option for what I need to do.
Command line:
ffmpeg -i ".
Original_100ms_PCR.ts" -map 0 -f mpegts -c: copy -pcr_period 100 ReBroadcasted_1100ms_PCR.ts
follow-up: 4 comment:3 by , 6 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:4 by , 6 years ago
Replying to cehoyos:
Please explain why this is invalid. The software does not create an MPEG-TS container that meets the standard of 100ms PCR rate. This affects playback synchronization and should be fixed.
comment:6 by , 6 years ago
Specifying -muxrate and -pcr_period does not change the rate of the PCR.
Original PCR:
PCR (s): 1.0
PCR (s): 1.147
PCR (s): 1.194
PCR (s): 1.245
PCR (s): 1.292
PCR (s): 1.34
PCR (s): 1.382
PCR (s): 1.428
PCR (s): 1.477
PCR (s): 1.525
PCR (s): 1.567
PCR (s): 1.612
PCR (s): 1.661
PCR (s): 1.711
PCR (s): 1.756
PCR (s): 1.803
PCR (s): 1.853
PCR (s): 1.903
PCR (s): 1.953
PCR (s): 2.009
PCR (s): 2.058
PCR (s): 2.103
PCR (s): 2.149
PCR (s): 2.199
PCR (s): 2.246
PCR (s): 2.292
PCR (s): 2.338
PCR (s): 2.39
PCR (s): 2.432
PCR (s): 2.478
PCR (s): 2.519
PCR (s): 2.562
PCR (s): 2.606
PCR (s): 2.655
PCR (s): 2.705
PCR (s): 2.75
PCR (s): 2.797
PCR (s): 2.841
PCR (s): 2.884
PCR (s): 2.929
PCR (s): 2.979
PCR (s): 3.029
PCR (s): 3.077
PCR (s): 3.133
PCR (s): 3.184
PCR (s): 3.234
PCR (s): 3.286
PCR (s): 3.337
PCR (s): 3.392
PCR (s): 3.443
PCR (s): 3.496
PCR (s): 3.542
PCR (s): 3.59
PCR (s): 3.651
PCR (s): 3.697
PCR (s): 3.744
PCR (s): 3.794
PCR (s): 3.842
PCR (s): 3.893
PCR (s): 3.949
PCR (s): 4.013
PCR (s): 4.054
PCR (s): 4.096
etc.
ffmpeg -i .\Original_100ms_PCR.ts -map 0 -f mpegts -c: copy -muxrate 10M -pcr_period 100 .\ReBroadcasted_1100ms_PCR.ts
New PCR:
PCR (s): 0.7004555555555556
PCR (s): 1.9460666666666666
PCR (s): 3.096477777777778
PCR (s): 4.238611111111111
PCR (s): 5.393088888888889
PCR (s): 6.608011111111111
PCR (s): 7.705033333333334
comment:7 by , 6 years ago
FFmpeg is not a TS remultiplexer in the true sense, it's extracting audio and video and then creating a totally new transport stream.
Kieran
comment:8 by , 6 years ago
So is there a way to specify the parameters of the MPEG-TS container it puts the new stream in? Or can the default values be modified to meet the standard? You used the term "remultiplexer" are you saying that the expected behavior is having to re-encode the video to get the expected PCR rate?
FFmpeg only ever copies the media streams, not any container-specific data.
You can configure the pcr interval using the pcr_period option (in milliseconds) if you desire a different interval then the muxer uses by default. But such behavior will not be copied from the input file.