mirror of
https://github.com/santinic/audiblez.git
synced 2025-04-13 09:38:57 +00:00
Merge pull request #82 from natankeddem/ffmpeg0
Some checks failed
Installing via pip and running / install-and-run-on-python-3-10 (push) Has been cancelled
Git clone and run / linux-git-clone-and-run (push) Has been cancelled
Git clone and run / windows-git-clone-and-run (push) Has been cancelled
Installing via pip and running / install-and-run-on-python-3-11 (push) Has been cancelled
Installing via pip and running / install-and-run-on-python-3-12 (push) Has been cancelled
Installing via pip and running / windows-git-clone-and-run (push) Has been cancelled
Some checks failed
Installing via pip and running / install-and-run-on-python-3-10 (push) Has been cancelled
Git clone and run / linux-git-clone-and-run (push) Has been cancelled
Git clone and run / windows-git-clone-and-run (push) Has been cancelled
Installing via pip and running / install-and-run-on-python-3-11 (push) Has been cancelled
Installing via pip and running / install-and-run-on-python-3-12 (push) Has been cancelled
Installing via pip and running / windows-git-clone-and-run (push) Has been cancelled
Improved ffmpeg arguments for m4b creation.
This commit is contained in:
commit
ef74c1bb15
1 changed files with 21 additions and 13 deletions
|
@ -313,25 +313,33 @@ def create_m4b(chapter_files, filename, cover_image, output_folder):
|
||||||
cover_file_path = Path(output_folder) / 'cover'
|
cover_file_path = Path(output_folder) / 'cover'
|
||||||
with open(cover_file_path, 'wb') as f:
|
with open(cover_file_path, 'wb') as f:
|
||||||
f.write(cover_image)
|
f.write(cover_image)
|
||||||
cover_image_args = ["-i", f'{cover_file_path}', "-map", "0:a", "-map", "2:v"]
|
cover_image_args = [
|
||||||
|
'-i', f'{cover_file_path}',
|
||||||
|
'-map', '2:v', # Map cover image
|
||||||
|
'-disposition:v', 'attached_pic', # Ensure cover is embedded
|
||||||
|
'-c:v', 'copy', # Keep cover unchanged
|
||||||
|
]
|
||||||
else:
|
else:
|
||||||
cover_image_args = []
|
cover_image_args = []
|
||||||
|
|
||||||
proc = subprocess.run([
|
proc = subprocess.run([
|
||||||
'ffmpeg',
|
'ffmpeg',
|
||||||
'-y', # overwrite output file without asking
|
'-y', # Overwrite output
|
||||||
'-i', f'{concat_file_path}', # input 0 file (audio)
|
|
||||||
'-i', f'{chapters_txt_path}', # input 1 file (chapters)
|
'-i', f'{concat_file_path}', # Input audio
|
||||||
*cover_image_args, # cover image
|
'-i', f'{chapters_txt_path}', # Input chapters
|
||||||
'-map', '0', # map all streams from input 0
|
*cover_image_args, # Cover image (if provided)
|
||||||
'-map_metadata', '1', # map metadata from input 1
|
|
||||||
'-c:a', 'copy', # copy audio codec
|
'-map', '0:a', # Map audio
|
||||||
'-c:v', 'copy', # copy video codec
|
'-c:a', 'aac', # Convert to AAC
|
||||||
'-disposition:v', 'attached_pic', # attach cover image
|
'-b:a', '64k', # Reduce bitrate for smaller size
|
||||||
'-c', 'copy', # copy codec
|
|
||||||
'-f', 'mp4', # format
|
'-map_metadata', '1', # Map metadata
|
||||||
f'{final_filename}' # output file
|
|
||||||
|
'-f', 'mp4', # Output as M4B
|
||||||
|
f'{final_filename}' # Output file
|
||||||
])
|
])
|
||||||
|
|
||||||
Path(concat_file_path).unlink()
|
Path(concat_file_path).unlink()
|
||||||
if proc.returncode == 0:
|
if proc.returncode == 0:
|
||||||
print(f'{final_filename} created. Enjoy your audiobook.')
|
print(f'{final_filename} created. Enjoy your audiobook.')
|
||||||
|
|
Loading…
Add table
Reference in a new issue