Avidemux Forum

Avidemux => Main version 2.6 => Topic started by: Blues on March 02, 2018, 04:11:45 PM

Title: Handling broken TS files
Post by: Blues 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?
Title: Re: Handling broken TS files
Post by: eumagga0x2a 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?).
Title: Re: Handling broken TS files
Post by: Blues 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.
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*)
Title: Re: Handling broken TS files
Post by: Blues 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/
Title: Re: Handling broken TS files
Post by: RoadRanger 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.
Title: Re: Handling broken TS files
Post by: Blues 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.
Title: Re: Handling broken TS files
Post by: eumagga0x2a on March 02, 2018, 11:51:11 PM
Quote from: Blues on March 02, 2018, 06:57:01 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. [...]

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.
Title: Re: Handling broken TS files
Post by: RoadRanger on March 02, 2018, 11:54:36 PM
Quote from: Blues 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.
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".
Title: Re: Handling broken TS files
Post by: Blues 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 (http://www.asclinux.com/tmp/cut6tail.ts) is 28 MB file which opens in Avidemux, but causes crash when saving.
Title: Re: Handling broken TS files
Post by: eumagga0x2a 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.

[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.
Title: Re: Handling broken TS files
Post by: RoadRanger on March 04, 2018, 02:04:20 AM
Quote from: Blues 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 (http://www.asclinux.com/tmp/cut6tail.ts) 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 :) .
Title: Re: Handling broken TS files
Post by: eumagga0x2a 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) (https://github.com/mean00/avidemux2/commit/0dd3d3d39795a0e75541ea488e620eb82af9f110).
Title: Re: Handling broken TS files
Post by: Blues 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.
Title: Re: Handling broken TS files
Post by: Jan Gruuthuse 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) (http://www.dipolnet.com/how_to_select_an_antenna_for_digital_tv_dvb-t__bib217.htm)
Title: Re: Handling broken TS files
Post by: Blues 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.
Title: Re: Handling broken TS files
Post by: Jan Gruuthuse on March 06, 2018, 06:39:24 AM
The wanted tv channel is not available on dvb-s/s2 (fta)?
Title: Re: Handling broken TS files
Post by: Blues on March 06, 2018, 03:43:21 PM
I wish. I used to have three satellite dishes with total 5 heads when I was living in Europe. Lots of FTA channels. This here is USA, to my knowledge there are no FTA channels here.
Title: Re: Handling broken TS files
Post by: Jan Gruuthuse on March 07, 2018, 07:05:31 AM
No idea if this will be of any help: http://www.ftalist.com/master.php
Title: Re: Handling broken TS files
Post by: Blues on March 07, 2018, 01:15:06 PM
Interesting list. However, they state clearly all FTA channels are temporary. http://www.ftalist.com/english.php Means you have to go channel hunting when you want to watch FTA.
I can receive New Orleans stations, about 85 km (53 miles) distance. The reception is quite good with my equipment, but there are occasional hick-ups. Thus, I need a video editor which can deal with broken files.
Title: Re: Handling broken TS files
Post by: fish on March 17, 2018, 02:22:17 PM
The most tolerant software I have found, for less than perfect DVB-T HD files is 'H264TS Cutter'. It runs only in Windows as far as I know and hasn't been updated for quite some time but it might get the job done in your case and be suitable for an older version of Windows.

Title: Re: Handling broken TS files
Post by: Blues on March 17, 2018, 09:10:33 PM
Sorry, there is no Windows in my household and never will be.