Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
|
|
Thread Tools | Search this Thread | Display Modes |
28th August 2013, 16:52 | #1 | Link |
Registered User
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
|
AVIsynth source plugin for MPEG-2 .ts files like Handbrake's input file handler?
Does anyone know of a source plugin that works with broadcast ATSC MPEG-2 .ts files that can accept a edited .ts file (with commercials removed) but keeps the audio and video in sync through the edit points?
I have used DGMPGDec for MPEG-2 content for years and years, but always found I had to process an edited .ts file in segments and join them all together at the end after carefully cutting or padding the .ac3 audio to match the video length in order to keep the audio and video in sync. It's doable, but it's pretty tedious and time consuming. Usually I found it worked better to take the original unedited .ts file and cut it into pieces rather than trying to use the edited file since the calculated AC3 delays won't necessarily be correct when cutting up an edited file, but are if you cut up an unedited file into segments to work with. I tried Handbrake on a whim to convert something for my tablet and was surprised to see it will take a edited .ts file with the commercials removed and it will remove excess .ac3 audio or excess video frames around the edit points and spit out a file that's got perfect A/V sync without pretty much no effort. Of course it's not as versatile and I miss MCTD and other AVIsynth plugins, but boy it sure is easy. So, back to my question... Is there a source plugin for AVIsynth that can do the same? Last edited by Stereodude; 28th August 2013 at 16:55. Reason: typo |
29th August 2013, 22:00 | #3 | Link |
Registered User
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
|
Hmm... I've been using DGDecNV for years, but admittedly haven't use it for much beyond Blu-Ray sources. So if I load one of my edited .ts files it will output an .ac3 file that's been trimmed or padded (with silence) appropriately at the edit points to stay in sync with the decoded video stream it serves into AVIsynth? I'm gonna have to try this when I get home.
|
30th August 2013, 04:26 | #4 | Link |
Registered User
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
|
Okay, so I tried it. The audio and video don't stay in sync. It seems to do the same thing as DGMPGDec. Is there some setting that needs to be used?
I dropped the file in DGDecNV, enabled audio processing and saved the project. It demuxed the audio and I encoded the video with x264 and then put the two together in a .mkv. I used the delay generated by DGDecNV and the audio was good through the first segment (before the first edit point where a commercial was removed). The A/V sync got worse as the file went on. |
30th August 2013, 05:19 | #6 | Link |
Registered User
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
|
Just as a point of reference, here's some of what Handbrake has in the log for one of these files. I've highlighted the lines that indicate the sort behavior I'm hoping to replicate in an AVIsynth source filter.
[01:06:38] file is MPEG Transport Stream with 188 byte packets offset 0 bytes [01:06:38] reader: first SCR 1384890927 id 0x11 DTS 1384890927 [01:06:38] encx264: min-keyint: 30, keyint: 300 [01:06:38] encx264: Encoding at constant RF 21.000000 x264 [warning]: --psnr used with psy on: results will be invalid! x264 [warning]: --tune psnr should be used if attempting to benchmark psnr! x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX AVX2 FMA3 LZCNT BMI1 BMI2 x264 [info]: profile High, level 3.1 [01:06:38] output track 1: ac3 in sync after skipping 592 bytes [01:06:38] mpeg2: "Chapter 1" (1) at frame 0 time 9009 [01:06:38] sync: first pts is 9009 [01:22:39] output track 1: ac3 in sync after skipping 1736 bytes [01:22:39] output track 1: ac3 in sync after skipping 616 bytes [01:32:11] output track 1: ac3 in sync after skipping 1024 bytes [01:32:11] output track 1: ac3 in sync after skipping 432 bytes [01:32:11] sync: adding 110 ms of silence to audio 0x14 start 75638706, next 75628800 [01:43:55] output track 1: ac3 in sync after skipping 1696 bytes [01:43:55] sync: audio 0x14 time went backwards 98 ms, dropped 3 frames (start 111266656, next 111275520) [01:43:58] sync: video time didn't advance - dropped 11 frames (delta 360 ms, current 111355134, next 111355693, dur 559) [01:55:24] output track 1: ac3 in sync after skipping 1760 bytes [01:55:24] sync: audio 0x14 time went backwards 72 ms, dropped 2 frames (start 145065800, next 145072320) [01:55:27] sync: video time didn't advance - dropped 7 frames (delta 200 ms, current 145142446, next 145145396, dur 2950) [02:08:06] output track 1: ac3 in sync after skipping 1416 bytes [02:08:06] output track 1: ac3 in sync after skipping 616 bytes [02:08:06] sync: audio 0x14 time went backwards 46 ms, dropped 1 frames (start 179032017, next 179036160) [02:08:09] sync: video time didn't advance - dropped 5 frames (delta 142 ms, current 179109326, next 179111559, dur 2233) [02:27:08] hb_ts_stream_decode - eof [02:27:08] reader: done. 13 scr changes [02:27:13] work: average encoding speed for job is 15.941417 fps [02:27:13] sync: got 77051 frames, 79286 expected [02:27:14] render: lost time: 43357314 (0 frames) [02:27:14] render: gained time: 43357314 (57740 frames) (0 not accounted for) [02:27:14] mpeg2 done: 77074 frames |
2nd September 2013, 11:22 | #7 | Link |
Registered User
Join Date: Oct 2001
Location: Thailand
Posts: 259
|
Have you tried editing it in avidemx?
You should be able to load that unedited .ts into avidemux, then cut out whatever portions you don't want (like in virtualdub), then save out to a new .ts. Both audio and video should be perfectly in synch. Then you can just frame serve that new video with DGMPGDec/DGDecNV to avisynth and do whatever. |
3rd September 2013, 17:18 | #8 | Link | |
Registered User
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
|
Quote:
FWIW, it appears that AVIdemux isn't really editing the native TS. It seems to demux the streams, cut them up, and then make a new .ts file with all new timecode, PIDs, etc all in one step. However, I edited a new recording with it and will see if the audio stays in sync. If it works, I suppose this is an option, but doesn't do me any good for recordings that were already edited. |
|
3rd September 2013, 18:10 | #9 | Link |
Registered User
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
|
I think I have overlooked a relatively simple solution (assuming it works). Extract the AC3 stream from the file Handbrake creates and generate an alternate video stream done just the way I want using DGMPGDec + AVIsynth. I figure this should be possible since it seems Handbrake makes all the time sync adjustments to the audio stream.
|
3rd September 2013, 23:57 | #10 | Link | |
Registered User
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
|
Quote:
Now to try the AVIdemux created .TS file. |
|
4th September 2013, 02:16 | #11 | Link |
Registered User
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
|
Converting the .TS file from AVIdemux using AVIsynth for video and using the demuxed source .ac3 file worked. The A/V sync was maintained. I did encounter some odd behaviour where DGMPGDec wouldn't extract the AC3 audio from the .TS. EAC3to extracted it fine though.
|
4th September 2013, 13:33 | #13 | Link | |
Registered User
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
|
Nevermind, seems it was user error. I mistakenly concluded that it would automatically extract track 0 when I had it set to "Demux Tracks" based on the wording in the User Manual.
Quote:
|
|
14th January 2014, 22:52 | #14 | Link | |
Registered User
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
|
Quote:
If I run the AVIdemux created .ts file through MPEG2Repair I get a log file full of these sorts of messages. Code:
Sequence Frame 38(9-B) / Time 0:00:01 : AudioWarning: Timestamp gap of 0.032000 sec. ending at file offset 2093966 Sequence Frame 423(4-B) / Time 0:00:14 : AudioWarning: Timestamp gap of 0.032000 sec. ending at file offset 25459922 Sequence Frame 1127(3-B) / Time 0:00:37 : AudioWarning: Timestamp gap of 0.032000 sec. ending at file offset 66644894 Sequence Frame 1831(5-P) / Time 0:01:01 : AudioWarning: Timestamp gap of 0.032000 sec. ending at file offset 110341734 However, I've subsequently tried outputting to mkv from AVIdemux instead of .ts and haven't found any issues with the AC3 audio during playback with MPC-HC. Unfortunately .mkv files can't be handled by DGMPGDec (though it will open them). DGDecNV, which can reportedly handle a .mkv, doesn't have deblocking capability for MPEG-2 like DGMPGDec does, so I still haven't really found a way to edit the .ts recording to a file I can both play back using MPC-HC to my TV and feed into AVIsynth with good audio sync. I know the MPEG-2 stream can be extracted from the .mkv but that's an extra step that makes things more complicated. I also still need to see if the extracted streams from the .mkv stay in sync or not after re-encoding and muxing. Last edited by Stereodude; 18th January 2014 at 22:12. |
|
18th January 2014, 22:13 | #15 | Link |
Registered User
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
|
FWIW, in the one test I've tried so far the extracted MPEG-2 and AC3 streams from a .mkv output by AVIdemux (from a edited ATSC .TS file) do stay in sync after the video has been run through AVIsynth, compressed, and remux'd with the AC3 audio stream spliced by AVIdemux.
Last edited by Stereodude; 18th January 2014 at 23:31. Reason: clarify |
|
|