diff --git a/bilix/ffmpeg.py b/bilix/ffmpeg.py index 3723a5bc..9f495d19 100644 --- a/bilix/ffmpeg.py +++ b/bilix/ffmpeg.py @@ -9,14 +9,29 @@ async def concat(path_lst: List[Path], output_path: Path, remove=True): - with tempfile.NamedTemporaryFile('w', dir=output_path.parent, delete=False) as fp: + with tempfile.NamedTemporaryFile( + 'w', dir=output_path.parent, delete_on_close=False + ) as fp: for path in path_lst: fp.write(f"file '{path.name}'\n") - cmd = ['ffmpeg', '-f', 'concat', '-safe', '0', '-i', fp.name, '-c', 'copy', '-loglevel', 'quiet', - str(output_path)] + fp.close() + cmd = [ + 'ffmpeg', + '-f', + 'concat', + '-safe', + '0', + '-i', + fp.name, + '-c', + 'copy', + '-loglevel', + 'quiet', + '-bitexact', + str(output_path), + ] # print(' '.join(map(lambda x: f'"{x}"', cmd))) - await run_process(cmd) - os.remove(fp.name) + await run_process(cmd) if remove: for path in path_lst: os.remove(path) @@ -26,8 +41,19 @@ async def combine(path_lst: List[Path], output_path: Path, remove=True): cmd = ['ffmpeg'] for path in path_lst: cmd.extend(['-i', str(path)]) - # for flac, use -strict -2 - cmd.extend(['-c', 'copy', '-strict', '-2', '-loglevel', 'quiet', str(output_path)]) + # for flac, use -strict experimental + cmd.extend( + [ + '-c', + 'copy', + '-strict', + 'experimental', + '-loglevel', + 'quiet', + '-bitexact', + str(output_path), + ] + ) # print(' '.join(map(lambda x: f'"{x}"', cmd))) await run_process(cmd) if remove: @@ -35,10 +61,29 @@ async def combine(path_lst: List[Path], output_path: Path, remove=True): os.remove(path) -async def time_range_clip(input_path: Path, start: int, t: int, output_path: Path, remove=True): - # for flac, use -strict -2 - cmd = ['ffmpeg', '-ss', f'{start:.1f}', '-t', f'{t:.1f}', '-i', str(input_path), '-codec', 'copy', '-strict', '-2', - '-loglevel', 'quiet', '-f', 'mp4', str(output_path)] +async def time_range_clip( + input_path: Path, start: int, t: int, output_path: Path, remove=True +): + # for flac, use -strict experimental + cmd = [ + 'ffmpeg', + '-ss', + f'{start:.1f}', + '-t', + f'{t:.1f}', + '-i', + str(input_path), + '-codec', + 'copy', + '-strict', + 'experimental', + '-loglevel', + 'quiet', + '-f', + 'mp4', + '-bitexact', + str(output_path), + ] # print(' '.join(map(lambda x: f'"{x}"', cmd))) await run_process(cmd) if remove: