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'
|
||||
with open(cover_file_path, 'wb') as f:
|
||||
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:
|
||||
cover_image_args = []
|
||||
|
||||
proc = subprocess.run([
|
||||
'ffmpeg',
|
||||
'-y', # overwrite output file without asking
|
||||
'-i', f'{concat_file_path}', # input 0 file (audio)
|
||||
'-i', f'{chapters_txt_path}', # input 1 file (chapters)
|
||||
*cover_image_args, # cover image
|
||||
'-map', '0', # map all streams from input 0
|
||||
'-map_metadata', '1', # map metadata from input 1
|
||||
'-c:a', 'copy', # copy audio codec
|
||||
'-c:v', 'copy', # copy video codec
|
||||
'-disposition:v', 'attached_pic', # attach cover image
|
||||
'-c', 'copy', # copy codec
|
||||
'-f', 'mp4', # format
|
||||
f'{final_filename}' # output file
|
||||
'-y', # Overwrite output
|
||||
|
||||
'-i', f'{concat_file_path}', # Input audio
|
||||
'-i', f'{chapters_txt_path}', # Input chapters
|
||||
*cover_image_args, # Cover image (if provided)
|
||||
|
||||
'-map', '0:a', # Map audio
|
||||
'-c:a', 'aac', # Convert to AAC
|
||||
'-b:a', '64k', # Reduce bitrate for smaller size
|
||||
|
||||
'-map_metadata', '1', # Map metadata
|
||||
|
||||
'-f', 'mp4', # Output as M4B
|
||||
f'{final_filename}' # Output file
|
||||
])
|
||||
|
||||
Path(concat_file_path).unlink()
|
||||
if proc.returncode == 0:
|
||||
print(f'{final_filename} created. Enjoy your audiobook.')
|
||||
|
|
Loading…
Add table
Reference in a new issue