kkroening/ffmpeg-python

Please add helper functions to easily combine streams of a static images with audio and video streams.

Emasoft opened this issue · 0 comments

Please add an helper function to add streams of a static image or a cover art image to audio and video files.
Mixing static images streams, cover arts, audio streams and metadata is very difficult with ffmpeg.

For example this is the command I found that works for embedding a jpeg cover image in mp4, m4a, m4b and mov audio files. Change something, and it does not display the cover on windows. Change some other thing, and it does not show the thumb on iOS. Miss a little thing, and it does not show any image on OSX during playback. Miss another, and it only works for mov but not for m4a. It took me 3 days to get it right:

$> ffmpeg -y -i "{audiofilename}" -i "{imagefilename}" -map 0:a -map 1:v -c:a copy -c:v:1 mjpeg -id3v2_version 3 -write_id3v1 1  -metadata:s:v "title=Album cover" -metadata:s:v "comment=Cover (front)"  -disposition:v:1 attached_pic "{audiofilename_noextension}_withcover.{extension}"

And this is the version of the same command for embedding covers in mp3 files:

$> ffmpeg -y -i "{imagefilename}" -i "{audiofilename}" -c:a copy -c:v copy -map 0:v -map 1:a -id3v2_version 3 -write_id3v1 1 -map_metadata 0:g -map_metadata 1:g -metadata:s:v 'title="Album cover"' -metadata:s:v 'comment="Cover (front)"' -disposition:v:0 attached_pic "{audiofilename_noextension}_cover.{extension}"

they look similar, but they are not! See all the small differences? Those are all essential, including quotation marks, metadata, order of the arguments and apostrophes nesting! 😱 (Note: The elements inside the curly brakets are stand-ins to be replaced by the corresponding string, like the format option in python).

And even after going crazy to find those, there are still issues! 😩
For example even if we explicitly add an output filename, ffmpeg sometimes still overwrites the original file when merging or embedding things (and using -n is not going to cut it, since sometimes you need to add some filtering or other things that require a yes in the batch operations..). Cover art in png format is hard to get right for some container formats like ogg or webm. Replacing thumbs of a video file with a png is tricky. Audio formats support of various video codecs is undocumented. Aspect ratio of the images is correct in some players, but wrong in others. And getting the mp3 thumbs to be displayed in iOS or iCloud Drive is an open quest...

Luckily you can use ffmpeg to quickly convert other image formats to jpg:

$> ffmpeg -i "{thumbnail_webp}" -qmin 1 -q:v 1 -bsf:v mjpeg2jpeg "{thumbnail_jpg}"

Please add some helper functions to make those functionalities easy to do with your library wrapper. 🙏
Thank you for this amazing lib! 😊