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. |
20th May 2016, 03:52 | #1 | Link | |
Registered User
Join Date: Feb 2004
Location: NYC
Posts: 124
|
Split ac3 in 5.1 and 2.0
Quote:
Code:
Time: 5981568 ms. Skipped: 768 bytes (Maybe: 13 ms.) Time: 5981581 ms. Written: 1 frames 2.0 ( 32 ms.) Time: 5981613 ms. Skipped: 256 bytes (Maybe: 10 ms.) Code:
eac3to file_n.ac3 file_n+1.ac3 -edit=1:39:41.568,55ms -silence ED: using 55ms there appears to have been fine, but I have another question. The original track has a delay of 10ms which eac3to says it could not fix: Code:
[a02] A remaining delay of +10ms could not be fixed. Code:
FileSize : 390893984 bytes ---------- First valid Header Time eq. : 6980249 ms. SamplCod : 0 (0:48, 1:44.1, 2:32 KHz.) BitRate : 448 Kb/s ChanMode : 7 (1:1/0, 2:2/0, 3:3/0, 4:2/1, 5:3/1, 6:2/2, 7:3/2) FrameSize: 1792 bytes ---------- Process ( 25.000000 fps is used for Trim) Time: 0 ms. Written: 10993 frames 5.1 ( 351776 ms.) Trim(0, 8793) ... Last edited by bilditup1; 20th May 2016 at 04:42. |
|
20th May 2016, 07:06 | #2 | Link |
Registered User
Join Date: Feb 2004
Location: NYC
Posts: 124
|
Running into some unexplained weirdness with eac3to and/or splitac3 on a different file. Not sure why but when I try to insert silences in this file, they are inserted one minute too early (in comparison with the timestamp given by the splitac3 log, which is in fact accurate). I have double-checked my math (ms --> hhmmss.ms) a dozen times on this, and it's not wrong either. The silences I'm attempting to insert are quite large, per the log:
Code:
FileSize : 289742432 bytes ---------- First valid Header Time eq. : 5173972 ms. SamplCod : 0 (0:48, 1:44.1, 2:32 KHz.) BitRate : 448 Kb/s ChanMode : 7 (1:1/0, 2:2/0, 3:3/0, 4:2/1, 5:3/1, 6:2/2, 7:3/2) FrameSize: 1792 bytes ---------- Process ( 29.970000 fps is used for Trim) Time: 0 ms. Written: 50980 frames 5.1 ( 1631360 ms.) Trim(0, 48891) Time: 1631360 ms. Written: 1873 frames 2.0 ( 59936 ms.) Time: 1691296 ms. Written: 40166 frames 5.1 ( 1285312 ms.) Trim(50688, 89208) Time: 2976608 ms. Written: 1870 frames 2.0 ( 59840 ms.) Time: 3036448 ms. Written: 11080 frames 5.1 ( 354560 ms.) Trim(91002, 101627) Time: 3391008 ms. Written: 942 frames 2.0 ( 30144 ms.) Time: 3421152 ms. Skipped: 768 bytes (Maybe: 109 ms.) Time: 3421261 ms. Written: 938 frames 2.0 ( 30016 ms.) Time: 3451277 ms. Written: 42827 frames 5.1 ( 1370464 ms.) Trim(103435, 144507) Time: 4821741 ms. Written: 1871 frames 2.0 ( 59872 ms.) Time: 4881613 ms. Written: 13423 frames 5.1 ( 429536 ms.) Trim(146302, 159174) ---------- End of File Total time: 5311149 ms. at EOF T. written: 158476 frames 5.1. T. written: 7494 frames 2.0. I can upload the file somewhere temporarily if anybody is interested enough to look at this. ED: The same thing just happened with another recording. Weirdness all around... Last edited by bilditup1; 20th May 2016 at 07:50. Reason: added file offer |
20th May 2016, 10:26 | #3 | Link | ||
Moderator
Join Date: Feb 2005
Location: Spain
Posts: 6,890
|
Quote:
But we never can be sure if that is correct, here show a strange equivalence: 768 bytes is the length of a typical 2.0 192 Kb/s 48 KHz frame (32 ms), here show 109 ms. I don't know if is a problem of my soft or a corrupt AC3 file. Quote:
__________________
BeHappy, AviSynth audio transcoder. |
||
20th May 2016, 21:02 | #4 | Link |
Registered User
Join Date: Feb 2004
Location: NYC
Posts: 124
|
These are the problem files where I have to add a minute to the edit parameter in eac3to to have the silence put in the right place. Plus their logs.
File1_final_track2_51.ac3 File1_final_track2.log File2_final_track2_51.ac3 File2_final_track2.log I can also put the file I was working on that didn't have this issue up if you think it'll be useful. Last edited by bilditup1; 22nd May 2016 at 23:23. Reason: Typo |
22nd May 2016, 23:15 | #6 | Link |
Registered User
Join Date: Feb 2004
Location: NYC
Posts: 124
|
|
23rd May 2016, 11:10 | #7 | Link |
Moderator
Join Date: Feb 2005
Location: Spain
Posts: 6,890
|
Thanks.
Well, your ac3's are a mix of this kinds: 5.1 448 Kb/s with 1792 bytes per frame 2.0 192 Kb/s with 768 bytes per frame 2.0 56 Kb/s with 224 bytes per frame Even there are some buggy frames with headers showing a framelength but finising with another framelength. Sorry, but my soft (SplitAc3) is not so smart to manage this situation. The extraction of 5.1 stream works very well, but fails when try to calculate the duration of 2.0 frames because there are two kind of frames. For this strange case (is the first time I see that) a manual resync is needed, like seems you already do.
__________________
BeHappy, AviSynth audio transcoder. |
23rd May 2016, 12:08 | #8 | Link |
Moderator
Join Date: Feb 2005
Location: Spain
Posts: 6,890
|
BTW if a have a TV capture with commercials, like seems you have, my way to recode the movie without commercials was this:
Using the log file, in your second post, with only the data of 5.1 streams: Code:
---------- Process ( 29.970000 fps) frames Trim ------ -------------------- Written: 50980 frames 5.1 (1631360 ms.) 48892 Trim(0, 48891) Written: 40166 frames 5.1 (1285312 ms.) 38521 Trim(x1, x1 + 38520) Written: 11080 frames 5.1 ( 354560 ms.) 10626 Trim(x2, x2 + 10625) Written: 42827 frames 5.1 (1370464 ms.) 41073 Trim(x3, x3 + 41072) Written: 13423 frames 5.1 ( 429536 ms.) 12873 Trim(x4, x4 + 12872) Trim(0, 48891) + Trim(x1, x1 + 38520) + Trim(x2, x2 + 10625) + Trim(x3, x3 + 41072) + Trim(x4, x4 + 12872) After that you can add the ac3 5.1 to video and must be in sync.
__________________
BeHappy, AviSynth audio transcoder. |
23rd May 2016, 23:46 | #9 | Link | |
Registered User
Join Date: Feb 2004
Location: NYC
Posts: 124
|
Quote:
|
|
23rd May 2016, 23:48 | #10 | Link | |
Registered User
Join Date: Feb 2004
Location: NYC
Posts: 124
|
Quote:
|
|
23rd May 2016, 23:51 | #11 | Link |
Registered User
Join Date: Feb 2004
Location: NYC
Posts: 124
|
Also, I'm curious - is there a way to add dummy SL/SR/C/LFE channels to a section of 2.0 AC3 and then cut it back into a 5.1 AC3 without doing any reencoding?
In any case. This software basically saved me these past few days. So thanks! Last edited by bilditup1; 24th May 2016 at 10:26. Reason: typo |
24th May 2016, 07:45 | #12 | Link | |
Moderator
Join Date: Feb 2005
Location: Spain
Posts: 6,890
|
Quote:
Nope, to convert a 2.0 to 5.1 you need recode the stream, at least all the 2.0 parts.
__________________
BeHappy, AviSynth audio transcoder. |
|
24th May 2016, 10:25 | #13 | Link | ||
Registered User
Join Date: Feb 2004
Location: NYC
Posts: 124
|
Quote:
Quote:
Wait, since my goal is to encode to AAC - is there a program for stitching m4a accurate enough that I could just downmix the 5.1 part to 2.0 and encode in AAC, then encode the 2.0 parts of the file separately, and then paste those in at the points indicated by the splitac3 log? |
||
2nd October 2018, 10:05 | #16 | Link | |
Moderator
Join Date: Feb 2005
Location: Spain
Posts: 6,890
|
Answer to Qarmaa pm:
Quote:
SplitAc3 try to extract two streams (5.1 and 2.0) mixed in a invalid ac3 stream (TV capture for instance). SpltAc3m try to extract multiple streams (5.1 and 2.0) mixed in a invalid ac3 stream (TV capture for instance). Both are here
__________________
BeHappy, AviSynth audio transcoder. Last edited by tebasuna51; 29th September 2021 at 16:38. |
|
20th October 2018, 10:58 | #17 | Link |
Registered User
Join Date: Sep 2017
Posts: 5
|
Thank you, tebasuna51. I decided to modify your program a bit, and wrote simple script on python to parse output and extract trims for VapourSynth.
Code:
#!/usr/bin/env python3 # -*- coding: utf-8 -*- '''Detect HDTV's AC3 Cuts''' import os import sys import re import subprocess import json from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter from colorama import init, Fore, Style ALLOWED_CONT = ('.mkv', '.mp4', '.ts', '.m2ts') def split_ac3(audio_track, framerate): print(f'{Fore.MAGENTA}{Style.BRIGHT}Begin to run SplitAc3...') process = subprocess.run(['SplitAc3', audio_track, str(framerate)], check=True, universal_newlines=True, stdout=subprocess.PIPE) if process.returncode or 'written: 0 frames' in process.stdout: return print(process.stdout) return tuple((int(t[0]), int(t[1])) for t in re.findall(r"Trim\((\d+), (\d+)\)", process.stdout)) def main(): init(autoreset=True) parser = ArgumentParser(description=__doc__, formatter_class=ArgumentDefaultsHelpFormatter) parser.add_argument('input', help='Source file') parser.add_argument('--fps', type=float, default=25.0) parser.add_argument('--no-junk', action='store_true', help='Remove junk') args = parser.parse_args() if not os.path.isfile(args.input): sys.exit(f'{Fore.RED}{Style.BRIGHT}File don\'t exists') source = args.input framerate = args.fps if os.path.splitext(source)[-1].lower() in ALLOWED_CONT: probe_out = ['ffprobe', '-v', 'quiet', '-print_format', 'json', '-show_format', '-show_streams', source] streams = json.loads(subprocess.check_output(probe_out).decode()) audio_streams = [] for s in streams['streams']: if s['codec_type'] == 'audio': if s['codec_name'] == 'ac3': audio_streams.append(s) if not audio_streams: sys.exit(f'{Fore.RED}{Style.BRIGHT}Source doesn\'t contain any Dolby Digital streams') audio_count = len(audio_streams) if audio_count == 1: print(f'{Fore.MAGENTA}{Style.BRIGHT}Source contains only one audio stream. Extracting...') audio_id = audio_streams[0]['index'] extract_out = os.path.splitext(source)[0] + '.ac3' else: # Creating list for matching list index and audio index inside container for i, au_choice_stream in enumerate(audio_streams): au_choice_codec = au_choice_stream['codec_name'] au_choice_channels = au_choice_stream['channels'] au_choice_lang = 'Und' if 'tags' in au_choice_stream and 'language' in au_choice_stream['tags']: au_choice_lang = au_choice_stream['tags']['language'] print(f'{i + 1}. {au_choice_lang}, {au_choice_channels} channel(s) (may be detected wrong)') choice_range = ', '.join(map(str, range(1, audio_count + 1))) while True: try: audio_key = int(input('choice audio to use (number): ')) if audio_key <= 0 or audio_key > audio_count: raise ValueError break except ValueError: print(f'{Fore.RED}{Style.BRIGHT}Wrong value. Possible values: {choice_range}') audio_id = audio_streams[audio_key - 1]['index'] extract = subprocess.run(('ffmpeg', '-hide_banner', '-i', source, '-map', f'0:{audio_id}', '-c:a', 'copy', extract_out, '-y'), check=True) if extract.returncode: sys.exit(f'{Fore.RED}{Style.BRIGHT}Error occurred during extracting audio') else: trims_list = split_ac3(extract_out, framerate) elif os.path.splitext(source)[-1].lower() == '.ac3': trims_list = split_ac3(source, framerate) else: sys.exit(f'{Fore.RED}{Style.BRIGHT}Can hande only this formats: ' + ', '.join(ALLOWED_CONT) + ', .ac3 ') if trims_list: trims_log = os.path.splitext(source)[0] + '.trims.log' print(f'{Fore.YELLOW}{Style.BRIGHT}Mixed stream detected. Video trims logged.') with open(trims_log, 'w') as f: json.dump(trims_list, f) else: print(f'{Fore.GREEN}{Style.BRIGHT}No mixed stream detected') if args.no_junk: stereo = os.path.splitext(source)[0] + '2_0.ac3' if os.path.isfile(stereo): os.remove(stereo) if __name__ == "__main__": main() Code:
ac3_trims = os.path.join(src_dir, feature_name, filename + '.trims.log') if os.path.isfile(ac3_trims): with open(ac3_trims) as f: trims_list = json.load(f) source = core.std.Splice([core.std.Trim(source, first=f, last=l) for f, l in trims_list]) |
Thread Tools | Search this Thread |
Display Modes | |
|
|