Author Topic: Handling broken TS files  (Read 1389 times)

Blues

  • Jr. Member
  • **
  • Posts: 77
Handling broken TS files
« on: March 02, 2018, 04:11:45 PM »
I'm using Tvheadend to record FTA channels. The TS files recorded have errors in them and Avidemux cannot handle them. (As a side note I have to mention Handbrake has no problems.) Is there a known tool to fix TS files so Avidemux won't crash when I load them?

eumagga0x2a

  • Moderator
  • Hero Member
  • *****
  • Posts: 2293
Re: Handling broken TS files
« Reply #1 on: March 02, 2018, 06:22:00 PM »
No matter how broken a file, crashing is not nice. If the latest nightly crashes as well, please provide samples. Avidemux can cope AFAIR with gaps up to 19 frames. Not sure, which strategies might be promising when extended parts of the stream are corrupted (seeking to the next keyframe maybe?).

Blues

  • Jr. Member
  • **
  • Posts: 77
Re: Handling broken TS files
« Reply #2 on: March 02, 2018, 06:57:01 PM »
Thanks for looking into this. Well, the sample would be 1.8 GB ... Actually Avidemux can open it and index it, but any action like remuxing into mkv will result in crash. I need to cut the ads out, and currently I'm unable to do it.
I tried several workarounds, so far no success. I can use ffmpeg to fix the video, but then audio goes out of sync. Not sure if ffmpeg has an option to keep sync, looking into this. So far only Handbrake can handle it without any issues, but I haven't found out how to force Handbrake insert keyframes frequently enough to enable me cutting commercials.

I did git pull and built Avidemux today.
Code: [Select]
Assert failed :0
 at line 199, file /home/saul/work/avidemux2/avidemux_plugins/ADM_demuxers/MpegTS/ADM_tsAudio.cpp
ADM_backTrack
ADM_tsAccess::getPacket(unsigned char*, unsigned int*, unsigned int, unsigned long*)



ADM_edAudioTrackFromVideo::getPacket(unsigned char*, unsigned int*, unsigned int, unsigned int*, unsigned long*)
ADM_audioStreamCopy::getPacket(unsigned char*, unsigned int*, unsigned int, unsigned int*, unsigned long*)
muxerFFmpeg::saveLoop(char const*)
admSaver::save()
A_Save(char const*)
A_SaveWrapper(char const*)
ADM_QT4_fileSel::GUI_FileSelWriteExtension(char const*, char const*, void (*)(char const*))
HandleAction_Save(Action)
HandleAction(Action)

QMetaObject::activate(QObject*, int, int, void**)
MainWindow::actionSignal(Action)
MainWindow::searchToolBar(QAction*)

QMetaObject::activate(QObject*, int, int, void**)
QToolBar::actionTriggered(QAction*)

QMetaObject::activate(QObject*, int, int, void**)
QToolButton::triggered(QAction*)
QMetaObject::activate(QObject*, int, int, void**)
QAction::triggered(bool)
QAction::activate(QAction::ActionEvent)

QAbstractButton::mouseReleaseEvent(QMouseEvent*)
QToolButton::mouseReleaseEvent(QMouseEvent*)
« Last Edit: March 02, 2018, 07:30:43 PM by Blues »

Blues

  • Jr. Member
  • **
  • Posts: 77
Re: Handling broken TS files
« Reply #3 on: March 02, 2018, 07:44:11 PM »
I fixed the audio, now Avidemux stalls on video. It does not crash, it just stops and can be terminated normally. Output from terminals can be seen here:
https://paste.pound-python.org/show/mdhmR1Bq5fD6HQjVMHn5/

RoadRanger

  • Jr. Member
  • **
  • Posts: 57
Re: Handling broken TS files
« Reply #4 on: March 02, 2018, 09:49:27 PM »
I often use FFMPEG to convert MTS/TS files into something more friendly. Try putting this batch file in a folder with the TS files you need to "fix" and running it.

It assumes you have FFMPEG.exe at the root of your drive.
« Last Edit: March 02, 2018, 09:53:51 PM by RoadRanger »

Blues

  • Jr. Member
  • **
  • Posts: 77
Re: Handling broken TS files
« Reply #5 on: March 02, 2018, 09:56:33 PM »
Thanks, but as I mentioned before with ffmpeg the audio goes out of sync. Also, the bat file is no use, it smells like Windows, my last Windows had BSoD in 2004, or was it 2003.

eumagga0x2a

  • Moderator
  • Hero Member
  • *****
  • Posts: 2293
Re: Handling broken TS files
« Reply #6 on: March 02, 2018, 11:51:11 PM »
Well, the sample would be 1.8 GB ... Actually Avidemux can open it and index it, but any action like remuxing into mkv will result in crash. [...]

Code: [Select]
Assert failed :0
 at line 199, file /home/saul/work/avidemux2/avidemux_plugins/ADM_demuxers/MpegTS/ADM_tsAudio.cpp
ADM_backTrack
ADM_tsAccess::getPacket(unsigned char*, unsigned int*, unsigned int, unsigned long*)

This sample might be helpful to find out, why the packet turns out to be too big for the buffer so we hit the assert (should it be split in smaller chunks?)

The log from MKV the internal ffmpeg fails to decode is not that interesting.

RoadRanger

  • Jr. Member
  • **
  • Posts: 57
Re: Handling broken TS files
« Reply #7 on: March 02, 2018, 11:54:36 PM »
Thanks, but as I mentioned before with ffmpeg the audio goes out of sync. Also, the bat file is no use, it smells like Windows, my last Windows had BSoD in 2004, or was it 2003.
If you don't run Windows you can still look in my batch file to see the options used - those may fix your audio sync problems. I was having those problems without the "-fflags +genpts".

Blues

  • Jr. Member
  • **
  • Posts: 77
Re: Handling broken TS files
« Reply #8 on: March 03, 2018, 11:23:44 AM »
I had no video tool to cut it, so I used head and tail to bisect it. Here is 28 MB file which opens in Avidemux, but causes crash when saving.

eumagga0x2a

  • Moderator
  • Hero Member
  • *****
  • Posts: 2293
Re: Handling broken TS files
« Reply #9 on: March 03, 2018, 12:08:36 PM »
Perfect, this is exactly the right way to cut MpegTS, thank you very much for the sample.

Code: [Select]
[TS Packet] PackLen=3848, avalailble=1834
[Ts Demuxer]*********Pes too long*******
[TS Packet]extra crap at the end 1830

Then it asserts as you stated above at ~48 seconds at avidemux2/avidemux_plugins/ADM_demuxers/MpegTS/ADM_tsAudio.cpp:199.

RoadRanger

  • Jr. Member
  • **
  • Posts: 57
Re: Handling broken TS files
« Reply #10 on: March 04, 2018, 02:04:20 AM »
I had no video tool to cut it, so I used head and tail to bisect it. Here is 28 MB file which opens in Avidemux, but causes crash when saving.
FWIW running this through my batch file and then using Avidemux on it doesn't crash like using the original file :) .

eumagga0x2a

  • Moderator
  • Hero Member
  • *****
  • Posts: 2293
Re: Handling broken TS files
« Reply #11 on: March 04, 2018, 10:13:53 AM »
Mean has fixed the crash in MpegTS demuxer: [MpegTS/Demux] Dont use packet with inconsistent size (offet>=size).

Blues

  • Jr. Member
  • **
  • Posts: 77
Re: Handling broken TS files
« Reply #12 on: March 04, 2018, 11:29:14 PM »
Thanks. I'm recording these shows and there will be more broken files, that's the nature of over the air transmission over long distance. Hopefully I can cut and recode them without doing voodoo next time.

Jan Gruuthuse

  • Hero Member
  • *****
  • Posts: 6052
Re: Handling broken TS files
« Reply #13 on: March 05, 2018, 06:49:35 AM »
If you're recording DVB-T, there are dvb-t directional yagi antenna to improve reception (radio amateur could provide you with more info). Improving reception would cancel most errors.

Technical info: How to select an antenna for digital TV (DVB-T)

Blues

  • Jr. Member
  • **
  • Posts: 77
Re: Handling broken TS files
« Reply #14 on: March 05, 2018, 03:24:21 PM »
Thanks, I used to be a radio amateur myself. It so happens I have the best antenna available (HD7698P Platinum HD Series Antenna). The next step would be stacking custom made antennas together. I'm not going to build anything like that on my roof. 80+ km distance is a challenge even with greatest antenna.