Wrongly halved framerate, ac3 audio unusable after a channel number switch

Started by eumagga0x2a, August 26, 2016, 10:32:59 PM

Previous topic - Next topic

eumagga0x2a

Probably closely related to http://avidemux.org/smif/index.php/topic,16994.0.html: The attached text file contains a link to a 170 MiB long transport stream fragment uploaded to WeTransfer. This testcase contains a h264 HD video and 4 audio tracks including an ac3 one (stream id 6) with the number of channels changing midway.

Avidemux fails to play this testcase properly as it wrongly assumes that it can safely halve the framerate:

  [checkForDoubledFps]  Checking for doubled FPS.., time increment ceiling = 18000
  [checkForDoubledFps]  Checking DTS...
  [checkTiming]  Good : 3080
  [checkTiming]  Bad  : 0
  [checkForDoubledFps]  Checking PTS...
  [checkTiming]  Good : 4596
  [checkTiming]  Bad  : 0
  [checkForDoubledFps]  We can safely halve fps
  [addFile]  Halving Fps...


When Avidemux saves the testcase in copy mode as mkv and the ac3 audio track is included (especially as the only audio track), both ffplay and mplayer stop playing audio at the point of the channel layout switch, mplayer showing audio timestamps not advancing from that moment on.

ffprobe reports:


ffprobe -report testcase-ac3-framerate-issue.ts
ffprobe version 3.0.2 Copyright (c) 2007-2016 the FFmpeg developers
  built with gcc 6.1.1 (GCC) 20160621 (Red Hat 6.1.1-3)
  configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-frei0r --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libcdio --enable-indev=jack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-openal --enable-opencl --enable-libopencv --enable-opengl --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvpx --enable-libx264 --enable-libx265 --enable-x11grab --enable-avfilter --enable-avresample --enable-postpr  libavutil      55. 17.103 / 55. 17.103
  libavcodec     57. 24.102 / 57. 24.102
  libavformat    57. 25.100 / 57. 25.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 31.100 /  6. 31.100
  libavresample   3.  0.  0 /  3.  0.  0
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
[file @ 0x107af40] Setting default whitelist 'file,crypto'
[mpegts @ 0x107a7c0] Format mpegts probed with size=2048 and score=100
[mpegts @ 0x107a7c0] stream=0 stream_type=5 pid=4f6 prog_reg_desc=
[mpegts @ 0x107a7c0] stream=1 stream_type=1b pid=13f7 prog_reg_desc=
[mpegts @ 0x107a7c0] stream=2 stream_type=3 pid=13f8 prog_reg_desc=
[mpegts @ 0x107a7c0] stream=3 stream_type=3 pid=13f9 prog_reg_desc=
[mpegts @ 0x107a7c0] stream=4 stream_type=6 pid=13fa prog_reg_desc=
[mpegts @ 0x107a7c0] stream=5 stream_type=6 pid=13fb prog_reg_desc=
[mpegts @ 0x107a7c0] stream=6 stream_type=6 pid=13fc prog_reg_desc=
[mpegts @ 0x107a7c0] stream=7 stream_type=3 pid=13fd prog_reg_desc=
[mpegts @ 0x107a7c0] stream=8 stream_type=6 pid=13fe prog_reg_desc=
[mpegts @ 0x107a7c0] stream=9 stream_type=6 pid=13ff prog_reg_desc=
[mpegts @ 0x107a7c0] Before avformat_find_stream_info() pos: 0 bytes read:458752 seeks:1
[mpegts @ 0x107a7c0] parser not found for codec none, packets or times may be invalid.
[mpegts @ 0x107a7c0] parser not found for codec dvb_teletext, packets or times may be invalid.
[mpegts @ 0x107a7c0] parser not found for codec dvb_teletext, packets or times may be invalid.
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] decode_slice_header error
[h264 @ 0x109d340] no frame!
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] decode_slice_header error
[h264 @ 0x109d340] no frame!
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] decode_slice_header error
[h264 @ 0x109d340] no frame!
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] decode_slice_header error
[h264 @ 0x109d340] no frame!
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] decode_slice_header error
[h264 @ 0x109d340] no frame!
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] decode_slice_header error
[h264 @ 0x109d340] no frame!
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] decode_slice_header error
[h264 @ 0x109d340] no frame!
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] decode_slice_header error
[h264 @ 0x109d340] no frame!
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] decode_slice_header error
[h264 @ 0x109d340] no frame!
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] decode_slice_header error
[h264 @ 0x109d340] no frame!
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] decode_slice_header error
[h264 @ 0x109d340] no frame!
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] decode_slice_header error
[h264 @ 0x109d340] no frame!
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] decode_slice_header error
[h264 @ 0x109d340] no frame!
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] decode_slice_header error
[h264 @ 0x109d340] no frame!
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] decode_slice_header error
[h264 @ 0x109d340] no frame!
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] decode_slice_header error
[h264 @ 0x109d340] no frame!
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] decode_slice_header error
[h264 @ 0x109d340] no frame!
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] decode_slice_header error
[h264 @ 0x109d340] no frame!
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] non-existing PPS 0 referenced
[h264 @ 0x109d340] decode_slice_header error
[h264 @ 0x109d340] no frame!
[h264 @ 0x109d340] Frame num gap 6 1
[h264 @ 0x109d340] Frame num gap 6 2
[h264 @ 0x109d340] Frame num gap 6 3
[h264 @ 0x109d340] Frame num gap 6 4
[h264 @ 0x109d340] no picture ooo
[h264 @ 0x109d340] Increasing reorder buffer to 2
[h264 @ 0x109d340] no picture ooo
[h264 @ 0x109d340] no picture ooo
[h264 @ 0x109d340] no picture ooo
[h264 @ 0x109d340] no picture ooo
[h264 @ 0x109d340] no picture ooo
[h264 @ 0x109d340] no picture ooo
[h264 @ 0x109d340] no picture
[h264 @ 0x109d340] no picture
[mpegts @ 0x107a7c0] Probe buffer size limit of 5000000 bytes reached
[NULL @ 0x109fe60] start time for stream 5 is not set in estimate_timings_from_pts
[NULL @ 0x10a2260] start time for stream 8 is not set in estimate_timings_from_pts
[NULL @ 0x10a2e20] start time for stream 9 is not set in estimate_timings_from_pts
[mpegts @ 0x107a7c0] PES packet size mismatch
[mpegts @ 0x107a7c0] PES packet size mismatch
[mpegts @ 0x107a7c0] PES packet size mismatch
[mpegts @ 0x107a7c0] PES packet size mismatch
[mpegts @ 0x107a7c0] PES packet size mismatch
[mpegts @ 0x107a7c0] Could not find codec parameters for stream 0 (Unknown: none ([5][0][0][0] / 0x0005)): unknown codec
Consider increasing the value for the 'analyzeduration' and 'probesize' options
[mpegts @ 0x107a7c0] After avformat_find_stream_info() pos: 0 bytes read:6082704 seeks:3 frames:946
Input #0, mpegts, from 'testcase-ac3-framerate-issue.ts':
  Duration: 00:02:05.98, start: 76453.944456, bitrate: 11319 kb/s
  Program 10301
  Program 10302
    Stream #0:0[0x4f6], 0, 1/90000: Unknown: none ([5][0][0][0] / 0x0005)
    Stream #0:1[0x13f7], 190, 1/90000: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 90k tbn, 100 tbc
    Stream #0:2[0x13f8](deu), 152, 1/90000: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 192 kb/s
    Stream #0:3[0x13f9](fra), 152, 1/90000: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 192 kb/s
    Stream #0:4[0x13fa](deu), 188, 1/90000: Subtitle: dvb_teletext ([6][0][0][0] / 0x0006)
    Stream #0:5[0x13fb](deu), 0, 1/90000: Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006) (hearing impaired)
    Stream #0:6[0x13fc](mul), 112, 1/90000: Audio: ac3 ([6][0][0][0] / 0x0006), 48000 Hz, 5.1(side), fltp, 448 kb/s
    Stream #0:7[0x13fd](mis), 152, 1/90000: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 192 kb/s
    Stream #0:8[0x13fe](fra), 0, 1/90000: Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
    Stream #0:9[0x13ff](deu), 0, 1/90000: Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
  Program 10303
  Program 10304
Unsupported codec with id 0 for input stream 0
detected 2 logical cores
Unsupported codec with id 94215 for input stream 4
[AVIOContext @ 0x10831a0] Statistics: 6082704 bytes read, 3 seeks


Avidemux can handle the content of the testcase fine once it has been remuxed e.g. into mkv with ffmpeg using appropriate -map options.

ffplay plays this file fine, no matter which audio track.

Jan Gruuthuse

saved in copy mode as mkv and the ac3 audio track as the only audio track.

Files (96.5 MB total) ArteHDtestcase-ac3-framerate-issue.mkv
Will be deleted on 4 September, 2016
Download link : https://we.tl/OaQsBZ6gH5
saved the your testvideo and could not find the issue with todays build bc4c29c        [build/clang] Try other alignment workarounds

plays fine in VLC 2.1.6 (Rincewind) and Videos 3.10.1, can you check if the issue is still there with ffplay and mplayer.
Quotestop playing audio at the point of the channel layout switch
I can't follow this? as there is only 1 track (ac3 audio track as the only audio track)

Editor] B- frame possible with that codec
[addFile]  [Editor] This is H264, check if we can fill missing PTS
  [ADM_setH264MissingPts]  We have 0 missing PTS
  [checkForDoubledFps]  Checking for doubled FPS.., time increment ceiling = 18000
  [checkForDoubledFps]  Checking DTS...
  [checkTiming]  Good : 4144
  [checkTiming]  Bad  : 0
  [checkForDoubledFps]  Checking PTS...
  [checkTiming]  Good : 6212
  [checkTiming]  Bad  : 0
  [checkForDoubledFps]  We can safely halve fps
  [addFile]  Halving Fps...
  [renderDisplayResize]  Render to 1280x720 zoom=2, old one =0 x 0, zoom=2, render=(nil)
  [init]  [Vdpau]Xv start
  [mixerCreate]  Creating vdpauMixer with width=1280, height=720 color=0
  [mixerCreate]  Vdpau Mixer : Enabling 0 features
  [spawnRenderer]  VDPAU init ok


eumagga0x2a

Thank you.

Are you able to play the testcase in Avidemux with audio and video in sync? I'm not. Avidemux believes that FPS of the video should be half of the correct value, resulting in a slow motion video and audio going more and more ahead of the video (best seen once the conductor enters the stage). This would be issue no. 1.

Now to issue no. 2:

I don't use VLC, but totem (GNOME Videos) exposes the same issue as mplayer and ffplay when playing the mkv file you generated: from 50.2 seconds into the video on, the sound stops, video continues. In the terminal window where mplayer was lauched, one can watch the audio timestamp remaining frozen at 50.2 while the video timestamp keeps advancing. This is the moment the channel layout in the ac3 track changes.

Quote from: Jan GruuthuseI can't follow this? as there is only 1 track (ac3 audio track as the only audio track)

An ac3 audio track can have different channel layouts. Both stereo (2ch: left and right) and a sort of a surround sound (https://en.wikipedia.org/wiki/5.1_surround_sound) are common.

eumagga0x2a

Maybe I'm wrong attributing AV async in Avidemux to the halving of FPS, the inability to play this TS in Avidemux with audio and video in sync would have another cause then.

Loading your mkv with the remuxed stream (h264 video + ac3 audio) in Avidemux confirms that there is really no audio data past 50.256, the console gets flooded with messages

[getPacket]  AudioGetPacket failed, audioSegment=0
  [getPacket]  ..and this is the last segment
  [refillPacketBuffer]  End of audio
  [getPCMPacket]  [Editor] Cannot refill audio
  [fillIncomingBuffer]  [Bridge] End of stream
  [getPacket]  AudioGetPacket failed, audioSegment=0
  [getPacket]  ..and this is the last segment


the last two lines repeating till the end of the video.

Jan Gruuthuse

Strange very strange.
@50116 is something strange going on, it is present in the original recording too, you hear the sound drop.
@51396 make here your start and save from here: you have the audio.

Files (57.6 MB total) 51396.mkv
Will be deleted on 4 September, 2016
Download link https://we.tl/zV2CbYF2Qo

see attached screenshots from avidemux saving started only AC-3 selected in avidemux
@ 50.116 2 channels / 6 channels, AC-3
@ 50.786 6 channels, AC-3
@ 51.396 2 channels / 6 channels, AC-3
2 different tracks in one AC3 audio stream?
Beyond my user experience, perhaps mean can see what is going on there.

mean

the thing is with TS you are allowed to change streams on the fly
6 channels -> stereo, maybe even AC3->MP2

But avidemux will sync on the 1st one it finds
So it might be that the stream switches to MP2 and so it cannot find AC3 header


Or something similar, just a thought

Jan Gruuthuse

I make a test recording tonight from arteHD (dvb-s2) "00:00 Thomas Hampson und Martin Grubinger in Concert" and see tomorrow if the same is going on.

eumagga0x2a

Thank you, could Avidemux maybe deal with similar channel layout switches in TS more graciously? They happen in DVB-S (don't know about DVB-S2) streams by Arte quite often. If I first use ffmpeg to remux the stream into a mkv

ffmpeg -i testcase-ac3-framerate-issue.ts -map 0:1 -map 0:6 -c copy testcase-ac3-framerate-issue-ffmpeg-remuxed.mkv

and then cut "testcase-ac3-framerate-issue-ffmpeg-remuxed.mkv" with Avidemux in copy mode, the audio is fine.

By the way, what do you think about the slow motion playback of the testcase with large and further growing A-V offset in Avidemux? As stated above, ffplay manages to play the stream without issues.

I hope that my sample TS file will help to find out what is really going on here.

Jan Gruuthuse

Astra 19.2Ã,°E
10743.75   H   51   Astra 1M (DVB-S) <= are you recording from this one?
11493.75   H   19   Pan Europe (DVB-S2) <= I'm using this one, with dvb-s2 STB (openpli)

eumagga0x2a

Quote from: Jan Gruuthuse on August 28, 2016, 07:17:22 PM
Astra 19.2Ã,°E
10743.75   H   51   Astra 1M (DVB-S) <= are you recording from this one?

Yes, from Astra, but the transponder should be 10729 MHz, and it turns out to be DVB-S2 :-o

Anyway, I'm really curious what actually happens in the TS at the spot where Avidemux cuts off the ac3 track.

Jan Gruuthuse

1st test does not confirm the issue.
Avidemux cut: program change to start concert, ac3 channel only.
Files (68.6 MB total) ArteHDac3test.mkv
Will be deleted on 5 September, 2016
Download link: https://we.tl/eAwGemw4nK

take note:  2 channels / 6 channels, AC-3 is not showing in the saved avidemux edit. see attached artehdac3.png.

I suspect a hardware recording issue? I would like to do a simultaneous recording test, but 1st you should check your STB and rescan the concerned transponders and make a new test recording. If that fails we can discuss how to proceed with simultaneous recording test.

Quote from: eumagga0x2a on August 28, 2016, 08:42:28 PM
Yes, from Astra, but the transponder should be 10729 MHz, and it turns out to be DVB-S2 :-o
That should not be the case?
10729 MHz V on 19.2Ã,°E is a pay TV transponder used by provider "Movistar+ (Astra)"

Current arte transponders see green highlighted:
arte:

ArteHD:



eumagga0x2a

Quote from: Jan Gruuthuse on August 29, 2016, 04:35:47 AM
1st test does not confirm the issue.
Avidemux cut: program change to start concert, ac3 channel only.
Files (68.6 MB total) ArteHDac3test.mkv

Thank you, though the source transport stream would have been preferable. Maybe arte HD was doing something terrible earlier but solved the problem on their part now? Your remuxed sample is impeccable.

QuoteI suspect a hardware recording issue? I would like to do a simultaneous recording test, but 1st you should check your STB and rescan the concerned transponders and make a new test recording. If that fails we can discuss how to proceed with simultaneous recording test.

I'll check it even if I don't think there was anything wrong with the hardware as apart from the ac3 audio issue exclusively at the beginning of some (but important for me) music programs on arte HD there were no problems like garbled data or drop-outs with the recorded streams. The next opportunity will arise next Sunday.

If it turns out that arte HD now avoids to trigger the issue in Avidemux, it reduces the urgency for me to pursue a solution on Avidemux part, sure (not mentioning that I was not aware of a workaround via ffmpeg till the day before yesterday). But it doesn't change anything for the better for people who would need a solution in Avidemux. The question is simply whether Mean finds it worth an effort to dig into the matter or not.

Quote
Quote from: eumagga0x2a on August 28, 2016, 08:42:28 PM
Yes, from Astra, but the transponder should be 10729 MHz, and it turns out to be DVB-S2 :-o
That should not be the case?
10729 MHz V on 19.2Ã,°E is a pay TV transponder used by provider "Movistar+ (Astra)"

My apologies, I've taken "Test Transponder-Frequenz" for Astra 19.2 in the LNB settings which is listed as 10729 MHz for the arte HD (DVB-S2!) transponder which is really 11494 MHz on Astra 19.2.

Again, I think that removing arte HD from the list of offenders who do things Avidemux doesn't like definitely helps me (thank you), but doesn't help with improving Avidemux.


Jan Gruuthuse

Quote from: eumagga0x2a on August 29, 2016, 04:39:59 PMThank you, though the source transport stream would have been preferable
The source transport stream recording is nearly 9 GB, will try to make a clean cut (same video part used to test.)
QuoteMaybe arte HD was doing something terrible earlier but solved the problem on their part now? Your remuxed sample is impeccable.
Arte sits within public German broadcasts. I'm using these for years now (weekly, ...). Only issues I've come across are transmissions interruptions,breaks (weather, plane, ...)

QuoteI'll check it even if I don't think there was anything wrong with the hardware
Could be the software on that hardware. Like firmware update (flash) or Linux updates (OpenPLi, ...)

QuoteAgain, I think that removing arte HD from the list of offenders who do things Avidemux doesn't like definitely helps me (thank you), but doesn't help with improving Avidemux.
This open for debate: If the input source is wrong? How far could/would you go without compromising the good input sources by trying to fix bad input source video within Avidemux.

If you find you still have ArteHD issues, we could agree to make the same recording at the same time. If the channel stream has a difference, one of the receivers does change something while recording and that should not be the case/happening.

Jan Gruuthuse

Think I got close enough with the cut (1.2 Gb dropped in front):
File (127 MB total) AC3UsedFootage.ts
Will be deleted on 6 September, 2016
Download link: https://we.tl/4gphxZcwfc

ac3 is the 3rd track. Switch this to 1st track see attached:

eumagga0x2a

Thank you, this was very helpful.

Can you please confirm that...

1) ...Avidemux is unable to play AC3UsedFootage.ts file with AV in sync?

2) when the ac3 track is set as the very first or the only audio track and in "Local playback downmixing" "No downmixing" is selected, only the first channel is played starting with the beginning of the concert on (look at the audio meter, on my system it corresponds to the left speaker)?

The channel configuration definitely switches on-the-fly in the stream (look again at the audio meter at the beginning of the sample where two channels are alive and later when only the first one pulses), but it doesn't disturb Avidemux much. The reason of severe problems with my sample was a different one (maybe there was really a gap in data at the point of # of channels switch?).