Batch Copy Cover Art from One Song to Another (Identical File Names) - batch-file

I'm looking for a way to copy the album art from one set of songs to another set of the same songs that don't have the album art. FFMPEG copies the text tags (artist, album, title...) perfectly, but will not copy the embedded album artwork.
I've been trying to batch convert my folder of MP3s into 128k AAC (using FFMPEG and the libfdk-aac codec) files to save space on my phone, but it hasn't copied my album art over to the new songs.
I used the following batch command:
FOR /F "tokens=*" %%G IN ('dir /b *.mp3') DO ffmpeg -i "%%G" -c:a libfdk_aac -b:a 128k "%%~nG.m4a"
EDIT: I tried using the following command to test it out, because stream 0:0 is the audio, and stream 0:1 is the JPEG, however it did not work:
ffmpeg -i Estranged.mp3 -map 0:0 -map 0:1 -c:a libfdk_aac -b:a 128k -c:v copy Estranged.m4a
Here's a paste of the log: http://pastebin.com/dZFsvR7F (I know, it's not the latest version. I had trouble compiling it myself but I'm currently working on it.)
Is there a way to copy the album art (or entire tag, if need be) from songs with an identical name in one folder to the songs in the new folder?
I.E. C:\Folder1\song.mp3 → C:\Folder2\song.m4a
Thanks.

ffmpeg -y -i input1.mp3 -i input2.mp3
-map 1 -codec copy
-map 0:1 -map_metadata 0 -id3v2_version 3
o.mp3
takes audio from input 2
takes metadata and album cover from input 1 in the highly-compatible id3v2.3 format
this is to be modified as needed

Related

Batch file to perform multiple conversions in a row

I'm trying to write a batch file that can be launched from Handbrake GUI with the "send file to" feature, that will split an MKV into chapters with MKVmerge, then convert all those new files into mp4s with ffmpeg. Handbrake passes only one argument into the batch file, the full file path of the output (surrounded by quotes). I'm very new to batch scripting and am having difficulty getting it all to work together -- all the individual parts work just fine when absolute paths are given. Here's the content of the .bat file:
START /WAIT "C:\Program Files\MKVToolNix\mkvmerge.exe -o output.mkv --split chapters:all %1"
for %%i in (*.mkv) do C:\ffmpeg\bin\ffmpeg.exe -i "%%i" -loop 1 -i "%%~dpi"\folder.jpg -map 1:v -map 0:a -c:a ac3 -b:a 640K -pix_fmt yuv420p -c:v libx264 -shortest -fflags +shortest -max_interleave_delta 100M "%%~ni.mp4"
Any glaring mistakes I'm making? I've been at this for hours reading SO threads and documentation, and can't figure it out for the life of me. Any help is appreciated, thanks in advance.

ffmpeg Converting files in place

I use ffmpeg on a daily basis to convert multiple video files to various other formats. Because of this I can't be moving ffmpeg and multiple batch files all over the place.
I have the folder C:\ffmpeg which contains ffmpeg.exe and all my different batch file converters for the different formats. I then have a shortcut on the desktop to the batch file which I can drag and drop video files onto to convert them.
As it stands, I use this to convert the video files in place.
FOR %%A IN (%*) DO (
"%~dp0\ffmpeg.exe" -i %%A -c:v libx264 -crf 22 -c:a aac %%A_Converted.mp4
)
Dragging and dropping the video file example.avi from the folder C:\Users\User\Documents\Folder results in the file example.avi_Converted.mp4 being created in the same location (perfect!).
I am wanting to remove the original file type, .avi from the new file name - so the output file is example_Converted.mp4. I can do this using ~n, shown in the following code sample, although the new file then gets created in C:\ffmpeg instead of in C:\Users\User\Documents\Folder.
FOR %%A IN (%*) DO (
"%~dp0\ffmpeg.exe" -i %%A -c:v libx264 -crf 22 -c:a aac "%%~nA_Converted.mp4"
)
Is there a way to do this so that the output file is created is the same place as the input file?

Batch overlay logo to directory of video files

I am using this command in windows 8 to overlay a logo (mywatermark.png , 400x200) to a video file:
ffmpeg -i E:\source\video01.mp4 -i E:\logo\mywatermark.png -filter_complex "[1:v]scale=100:50 [ovrl], [0:v][ovrl
]overlay=W-w-10:H-h-10[watermark]" -map "[watermark]" -map 0:a -codec:v libx264 -preset veryfast -crf 18 -codec:a copy E:\output\video01.mp4
as you can see I am first rescaling my logo to 100:50 pixels, and then overlaying it to the bottom right corner.
This is working for me.
My question is:
How can I repeat this to all of the videos in the same directory, adding the same logo to all?
I want to save the output video files same as the original, of course in different folder. However, not to forget that my source video files are of different quality and resolution.
How can I add a parameter to the command line to proportionnally scale the logo in regard to the video file resolution?
I am afraid that if I don't do this, the logo will be small in one file and bigger in another.
thanks a lot
How can I repeat this to all of the videos in the same directory, adding the same logo to all?
Windows command line processor - cmd.exe - offers the command FOR for executing a command on all files in a directory.
#echo off
for %%I in ("E:\source\*.mp4") do ffmpeg.exe -i "%%I" -i E:\logo\mywatermark.png -filter_complex "[1:v]scale=100:50 [ovrl], [0:v][ovrl]overlay=W-w-10:H-h-10[watermark]" -map "[watermark]" -map 0:a -codec:v libx264 -preset veryfast -crf 18 -codec:a copy "E:\output\%%~nI.mp4"
Running in a command prompt window for /? or help for outputs help for this command over several display pages. As help of command FOR is long, it is advisable to redirect the output help into a text file and read the file with Notepad or any other text editor.
for /? >"%USERPROFILE%\Desktop\Help_FOR.txt"
Notepad "%USERPROFILE%\Desktop\Help_FOR.txt"
In above batch code %%I is replaced by name of current *.mp4 file with full path and %%~nI with just name of current *.mp4 file without path and without file extension.
As #LordNeckbeard commented, you can use the scale2ref filter to proportionally scale the watermark, like so
ffmpeg -i E:\source\video01.mp4 -loop 1 -i E:\logo\mywatermark.png \
-filter_complex "[1:v][0:v]scale2ref=iw/8:-1[ovrl][0v]; \
[0v][ovrl]overlay=W-w-10:H-h-10[watermark]" \
-map "[watermark]" -map 0:a \
-codec:v libx264 -preset veryfast -crf 18 -c:a copy E:\output\video01.mp4
The iw/8 specifies that the watermark's width and height be scaled to 1/8th of the base video's width and height. The scale2ref filter has the same options available as the scale filter.

ffmpeg batch script that combines multiple audio clips with one image > mp4

I found this script in another thread and edited it to make this:
#echo off
for %%F in (*.jpg) do (
if exist "%%~nF.mp3" (
ffmpeg -loop 1 -i "%%~nF.jpg" -i "%%~nF.mp3" -acodec libvo_aacenc -vcodec mpeg4 -shortest "%%~nF.mp4"
)
)
It combines all mp3 files with all jpeg files that share the same filename into a mp4 video with the static image running.
But the problem is - if I want to convert more than one mp3 file using the same image (let's say three mp3s), I have to duplicate the same jpeg image three times!
For example, if I have three Michael Jackson mp3 files:
MJ1.mp3
MJ2.mp3
MJ3.mp3
I would need to create:
MJ1.jpg
MJ2.jpg
MJ3.jpg
But really I only need one image for all three mp3s.
What edits do I need to make to the script combine all mp3s with one jpeg file? Let's say I wanted every mp3 file in the folder to convert with default.jpg. How would I do this?
Invert the loop. Instead of iterating over the images, iterate over the sound files.
#echo off
for %%F in (*.mp3) do (
ffmpeg -loop 1 -i "default.jpg" -i "%%~nxF" -acodec libvo_aacenc -vcodec mpeg4 -shortest "%%~nF.mp4"
)

ffmpeg batch retains old filetype in name

I'm using the following ffmpeg script to convert all .mp4 files in the folder to .webm.
for %%A IN (*.mp4) DO ffmpeg -i "%%A" -c:v libvpx -crf 4 -b:v 3M -c:a libvorbis "%%A.webm"
I am trying to make it go from "xxx.mp4" to "xxx.webm"
However when I run the script the file name goes from "xxx.mp4" to "xxx.mp4.webm"
Any suggestions are highly appreciated.
Use %%~nA.webm to select the name-part of the filename.
see for /? from the prompt or documentation.
To recursively convert in webm all the mp4 video files in nested folders, you can try this command:
find '~/Video/' -iname '*.mp4' -exec bash -c 'D=$(dirname "{}"); B=$(basename "{}"); mkdir "$D/webm/"; ffmpeg -i "{}" -c:v libvpx -crf 4 -b:v 3M -c:a libvorbis "$D/webm/${B%.*}.webm"' \;
It will create a folder named "webm" inside the one with mp4 video files and, inside the "webm" folder, it will save relative webm files, without keeping the old file extension in the name.

Resources