VideoHelp Forum
+ Reply to Thread
Results 1 to 26 of 26
Thread
  1. I need some help with bulk combining hundreds of audio files (mp3s) that I fully own with the same picture to create mp4 files with identical names as the audios. It would be even better if I could do this on a parent directory with the audio files spread out in subdirectories rather than have all the audios in one large folder.

    I've tried using ffmpeg but am unable to do this in batch and on files with names that includes spaces. There are also seems to be some discrepancies between different ffmpeg versions but I'm using the latest one (20171229)

    Edit:

    I've used the following command for single files and no spaces but have been unable to write something for bulk action ffmpeg -loop 1 -framerate 2 -i input.png -i audio.m4a -c:v libx264 -preset medium -tune stillimage -crf 18 -c:a copy -shortest -pix_fmt yuv420p output.mkv

    These are the references and commands that I've used without any success
    https://forum.videohelp.com/threads/354099-Batch-combining-jpg-with-audio#post2225351
    https://stackoverflow.com/questions/13688374/ffmpeg-batch-image-multiple-audio-to-video
    Last edited by MD_89; 31st Dec 2017 at 12:27.
    Quote Quote  
  2. With the picture as metadata or a video track?

    files with names that includes spaces
    Use quotation marks.
    Quote Quote  
  3. A separate picture, i.e. not the cover art. But I want to use the same picture for each audio/video

    Edit: I want to use the picture as a still in the videos
    Last edited by MD_89; 31st Dec 2017 at 12:35.
    Quote Quote  
  4. Originally Posted by MD_89 View Post
    It would be even better if I could do this on a parent directory with the audio files spread out in subdirectories rather than have all the audios in one large folder. I've tried using ffmpeg but am unable to do this in batch and on files with names that includes spaces.
    Subdirectories can be tricky and or you will write result in same subfolder as source (e.g. %~f1 Expand %1 to a Fully qualified path name for output) or you need to recreate first subdirectory structure in some other place.
    Spaces in name and in folder can be very tricky for ffmpeg (not for windows environment) and even quotation may not work, i usually use variable as it seem to be processed correctly by ffmpeg however some limitations still exist - i assume special escaping is required from ffmpeg perspective.
    Quote Quote  
  5. With Picture.jpg being you picture you could try a batch job like (Windows) for your d: drive:

    Code:
    for /f "tokens=*" %%g in ('dir /b /s "d:\*.mp3"') do (
     ffmpeg -loop 1 -i "Picture.jpg" -i "%%g" -c:a copy -c:v libx264 -shortest "%%~ng.mp4"
    )
    Quote Quote  
  6. Originally Posted by pandy View Post
    Originally Posted by MD_89 View Post
    It would be even better if I could do this on a parent directory with the audio files spread out in subdirectories rather than have all the audios in one large folder. I've tried using ffmpeg but am unable to do this in batch and on files with names that includes spaces.
    Subdirectories can be tricky and or you will write result in same subfolder as source (e.g. %~f1 Expand %1 to a Fully qualified path name for output) or you need to recreate first subdirectory structure in some other place.
    Spaces in name and in folder can be very tricky for ffmpeg (not for windows environment) and even quotation may not work, i usually use variable as it seem to be processed correctly by ffmpeg however some limitations still exist - i assume special escaping is required from ffmpeg perspective.
    Fine, I'll give up on subdirectories, although I don't mind if the videos end up the source folders, in the same structure elsewhere or in one folder. That's less of a problem.

    Any other tips? It doesn't have to be ffmpeg. However, that's the only free solution I found that would allow me to select the background picture of the video, does not watermark the videos and works in bulk
    Quote Quote  
  7. Originally Posted by videobruger View Post
    With Picture.jpg being you picture you could try a batch job like (Windows) for your d: drive:

    Code:
    for /f "tokens=*" %%g in ('dir /b /s "d:\*.mp3"') do (
     ffmpeg -loop 1 -i "Picture.jpg" -i "%%g" -c:a copy -c:v libx264 -shortest "%%~ng.mp4"
    )

    Thank you, but I made one big silly mistake. I used the word batch as a synonym for bulk and now realise that's something else. Will this solution work if I just run CMD as usual and run this script?

    When I run it, it says that my picture with that name (which is in the directory) does not exist
    Last edited by MD_89; 31st Dec 2017 at 13:03.
    Quote Quote  
  8. picture.jpg must be in the same folder as the the batch file*. Or just use the full path to the image.


    * This may vary depending on what OS you are running. I seem to recall that old versions of Windows ran batch files in C:\users\username\ rather than the folder in which they appear.
    Last edited by jagabo; 31st Dec 2017 at 14:11.
    Quote Quote  
  9. I added the full url and received a error with a link to the picture and "Invalid argument"

    When I added the picture to C:\users\username\, I got error saying "%%g: No such file or directory"

    I'm using Windows 10.
    Quote Quote  
  10. Update:

    I got it to work by only using one % instead of two (since I didn't run it in batch). However the output folder became C:\users\username\. Is there any way that I can change that?
    Quote Quote  
  11. Look for Variable substitution HERE.
    Quote Quote  
  12. Originally Posted by MD_89 View Post
    the output folder became C:\users\username\. Is there any way that I can change that?
    Add a path to the output filespec. Change "%%~ng.mp4" to "C:\some\folder\%%ng.mp4" or "%%~dpng.mp4" to put the output files in the same folder as the input files.
    Quote Quote  
  13. Originally Posted by jagabo View Post
    Originally Posted by MD_89 View Post
    the output folder became C:\users\username\. Is there any way that I can change that?
    Add a path to the output filespec. Change "%%~ng.mp4" to "C:\some\folder\%%ng.mp4" or "%%~dpng.mp4" to put the output files in the same folder as the input files.
    Thank you! Worked like a charm. Any suggestions on how I can transfer the metadata to the mp4 copies as well?
    Quote Quote  
  14. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    Make a batch file with:

    Code:
    for /R %%g in ("*.mp3") do (
    ffmpeg -loop 1 -i "Bud_009.jpg" -i "%%g"^
     -map_metadata 1^
     -map_metadata:s:v 1:s:v^
     -map_metadata:s:a 1:s:a^
     -c:a copy -c:v libx264^
     -shortest "%%~dpng.mp4"
    )
    Put it in the parent directory and run from a CMD prompt from that parent directory. It copied all of the mp3's in the parent and the recursive folders and the metadata in my test.

    Image
    [Attachment 44252 - Click to enlarge]

    Image
    [Attachment 44253 - Click to enlarge]
    Quote Quote  
  15. If you can live with an all black (or other color) video instead of a jpg image you can get much faster conversions with something like:

    Code:
    for /R %%g in ("*.mp3") do (
     "G:\Program Files\ffmpeg\bin\ffmpeg.exe" -y -f lavfi -i color=c=black:s=640x480:r=1.0 -i "%%g"^
     -map_metadata 1^
     -map_metadata:s:v 1:s:v^
     -map_metadata:s:a 1:s:a^
     -c:a copy -c:v libx264 -preset ultrafast -tune stillimage^
     -shortest "%%~dpng.mp4"
    )
    Quote Quote  
  16. Originally Posted by jagabo View Post
    If you can live with an all black (or other color) video instead of a jpg image you can get much faster conversions with something like:

    Code:
    for /R %%g in ("*.mp3") do (
     "G:\Program Files\ffmpeg\bin\ffmpeg.exe" -y -f lavfi -i color=c=black:s=640x480:r=1.0 -i "%%g"^
     -map_metadata 1^
     -map_metadata:s:v 1:s:v^
     -map_metadata:s:a 1:s:a^
     -c:a copy -c:v libx264 -preset ultrafast -tune stillimage^
     -shortest "%%~dpng.mp4"
    )
    the image part is the main reason why I'm doing this "manually" and not using conversion softwares
    Quote Quote  
  17. One other thing you can do to speed up processing is reduce the frame rate (1 fps instead of the default 25 fps?) before importing the image. Using a fast preset for x264lib and stillimage tuning will help too. Those changes increased the encoding rate by about 20 fold on my computer. Some programs/devices might have trouble with 1 fps. though.

    Budman1's batch file (and hence my mod) produces an empty mp4 file if the mp3 file has no metadata.
    Last edited by jagabo; 1st Jan 2018 at 13:55.
    Quote Quote  
  18. Originally Posted by jagabo View Post
    One other thing you can do to speed up processing is reduce the frame rate (1 fps instead of the default 25 fps?) before importing the image. Using a fast preset for x264lib and stillimage tuning will help too. Those changes increased the encoding rate by about 20 fold on my computer. Some programs/devices might have trouble with 1 fps. though.

    Budman1's batch file (and hence my mod) produces an empty mp4 file if the mp3 file has no metadata.
    Do you mind explaining how I can do those things? I'm completely new to scripts.

    Also, is there any way to solve the problem of empty mp4 files when the mp3 files have no metadata?

    I'm also curious about how the script would look like if I instead wanted to use a different picture depending on which folder the mp3 file is in, i.e. using the picture titled "Image.jpg" that is found in the same folder as the mp3 files, instead of using the same picture for all mp3 files.

    I'm very grateful for all help thus far and realise you have better things to do than to answer my questions so feel free to ignore these requests if you've had enough of this
    Quote Quote  
  19. Faster processing using Budman1's batch file:

    Code:
    for /R %%g in ("*.mp3") do (
    ffmpeg -r 1.0 -loop 1 -i "Bud_009.jpg" -i "%%g"^
     -map_metadata 1^
     -map_metadata:s:v 1:s:v^
     -map_metadata:s:a 1:s:a^
     -c:a copy -c:v libx264 -preset superfast -tune stillimage^
     -shortest "%%~dpng.mp4"
    )
    "-r 1.0" on the second line sets the frame rate to 1.0 fps. x264 preset and tuning is on line 6.

    Using a different image for each folder for each is easy if you put the images in the folders. Then you can just change

    Code:
    -i "Bud_009.jpg"
    to

    Code:
    -i "%%~dpgBud_009.jpg"
    I think you can test the errorlevel when ffmpeg exits. If there's an error you can run a separate encoding without the metadata commands. I'll look into that later.
    Quote Quote  
  20. Originally Posted by jagabo View Post
    Faster processing using Budman1's batch file:

    Code:
    for /R %%g in ("*.mp3") do (
    ffmpeg -r 1.0 -loop 1 -i "Bud_009.jpg" -i "%%g"^
     -map_metadata 1^
     -map_metadata:s:v 1:s:v^
     -map_metadata:s:a 1:s:a^
     -c:a copy -c:v libx264 -preset superfast -tune stillimage^
     -shortest "%%~dpng.mp4"
    )
    "-r 1.0" on the second line sets the frame rate to 1.0 fps. x264 preset and tuning is on line 6.

    Using a different image for each folder for each is easy if you put the images in the folders. Then you can just change

    Code:
    -i "Bud_009.jpg"
    to

    Code:
    -i "%%~dpgBud_009.jpg"
    I think you can test the errorlevel when ffmpeg exits. If there's an error you can run a separate encoding without the metadata commands. I'll look into that later.

    Thanks, it worked. However the screen is black initially in the videos with this method. So there's a tradeoff that I need to consider.
    Quote Quote  
  21. Originally Posted by MD_89 View Post
    the screen is black initially in the videos with this method.
    For how long? I'm only seeing a flash of black before the video starts. Probably less than 1/10 second.
    Quote Quote  
  22. Originally Posted by jagabo View Post
    Originally Posted by MD_89 View Post
    the screen is black initially in the videos with this method.
    For how long? I'm only seeing a flash of black before the video starts. Probably less than 1/10 second.
    For me the "flash" of black was 2.5-3 seconds long
    Quote Quote  
  23. Originally Posted by jagabo View Post
    Faster processing using Budman1's batch file:

    Code:
    for /R %%g in ("*.mp3") do (
    ffmpeg -r 1.0 -loop 1 -i "Bud_009.jpg" -i "%%g"^
     -map_metadata 1^
     -map_metadata:s:v 1:s:v^
     -map_metadata:s:a 1:s:a^
     -c:a copy -c:v libx264 -preset superfast -tune stillimage^
     -shortest "%%~dpng.mp4"
    )
    "-r 1.0" on the second line sets the frame rate to 1.0 fps. x264 preset and tuning is on line 6.

    Using a different image for each folder for each is easy if you put the images in the folders. Then you can just change

    Code:
    -i "Bud_009.jpg"
    to

    Code:
    -i "%%~dpgBud_009.jpg"
    I think you can test the errorlevel when ffmpeg exits. If there's an error you can run a separate encoding without the metadata commands. I'll look into that later.

    I followed the above instructions but am having three issues

    1. As for md_89, the screen is black initially
    2. The quality of the image that is used appears somewhat reduced with this script. How can I ensure a high resolution of the image without it resulting ridiculously large files and slow processing?
    3. Finally and most importantly, I get the following error on some files: "track 1: muxing mp3 at *** is not standard". How can I address this in bulk without losing audio quality? Should I re-encode or stream copy all audios first? Can I do it in the same instance as I merge the files? Any suggestions on scripts?
    Quote Quote  
  24. Originally Posted by DennisO View Post
    1. As for md_89, the screen is black initially
    Some players don't like slow frame rates like 1 fps. Try changing the frame rate to a more normal video frame rate like 24 fps or 30 fps. The resulting file will be bigger and it will take longer to encode. Or use a different player.

    Originally Posted by DennisO View Post
    2. The quality of the image that is used appears somewhat reduced with this script. How can I ensure a high resolution of the image without it resulting ridiculously large files and slow processing?
    Video is normally encoded with the colors at half the resolution (each axis). So you expect to see very small colored text and objects, and sharp colored edges, become blurry. For example:

    https://forum.videohelp.com/threads/319360-DVD-LAB-PRO-color-map#post1977264

    Are you seeing something worse than that?

    Originally Posted by DennisO View Post
    3. Finally and most importantly, I get the following error on some files: "track 1: muxing mp3 at *** is not standard". How can I address this in bulk without losing audio quality? Should I re-encode or stream copy all audios first? Can I do it in the same instance as I merge the files? Any suggestions on scripts?
    What's the exact error message? Is it VBR or CBR mp3?
    Last edited by jagabo; 28th Nov 2018 at 20:43.
    Quote Quote  
  25. Originally Posted by jagabo View Post
    What's the exact error message? Is it VBR or CBR mp3?
    I don't know about VBR vs CBR. This is the error message that I was referring to (The number of hz varies though):
    Code:
    [mp4 @ 00000182ecf7e500] track 1: muxing mp3 at 11025hz is not standard, to mux anyway set strict to -1
    Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
    Error initializing output stream 0:0 --

    I also noticed another "red error message" that reads: "Stream specifier v does not match any streams."
    Consequently, those audios aren't converted. Any suggestions on how I can address this?


    Finally, I also get this following "yellow error message":
    Code:
    [mp3 @ 0000026a489a6300] Estimating duration from bitrate, this may be inaccurate
    Is that a cause of concern?
    Last edited by DennisO; 29th Nov 2018 at 09:52.
    Quote Quote  
  26. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    Probable errors show up if you include
    '-map_metadata:v 1:v^'
    in my script because it is for VIDEO Metadata and there is none, just an image and an Audio.
    Remove that portion.

    Also tried playing resulting MP4 in VLC and there is indeed a Black screen at the beginning. Apparently it doesn't like to show the image until the audio starts, which is after the image which had no audio. Windows Media player and Potplayer do not show the Black screen.

    There is no Black frames as tested with FFprobe and Avisynth.:

    Image
    [Attachment 47346 - Click to enlarge]
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!