VideoHelp Forum

Our website is made possible by displaying online advertisements to our visitors. Consider supporting us by disable your adblocker or Try ConvertXtoDVD and convert all your movies to DVD. Free trial ! :)
+ Reply to Thread
Results 1 to 15 of 15
Thread
  1. Hello all! Was hoping I could procure a little help here, I'm in a bit over my head. I'm using FFmpeg for Windows, trying to write a batch file that'll transfer a large folder of MKV videos into MP4 containers. No conversion or video format changes, just a container change.

    I have been using the line

    ffmpeg -i INPUT.mkv -codec:a copy -codec:v copy OUTPUT.mp4

    This works well, but it only copies across one audio track (my MKV has two), and it requires me to name the input and output.

    What I'd like is a batch file that performs that action on all MKVs in a certain folder, one at a time, and outputs them with an identical name. Something like

    ffmpeg -i f:\videos\*.mkv -codec:a copy -codec:a2 copy -codec:v copy f:\newvideos\*.mp4

    If possible, it would erase the MKV after it generates the MP4 version.

    I don't know enough about ffmpeg or about batch files to write that properly, though. Can someone offer me a little help and show me how that's done, if it can be at all? I'd very much appreciate it.
    Quote Quote  
  2. I don't recommend auto erase , because if there are errors, you lost your source file. (remove the del line)

    This is for copying 1video and 1st 2 audio streams into mp4
    Code:
    for %%a in ("*.mkv") do ffmpeg -i %%a -map 0:0 -vcodec copy -map 0:1 -acodec copy -map 0:2 %%~na.mp4
    del *.mkv
    pause
    Quote Quote  
  3. In case you haven't used batch files before

    1) place copy of ffmpeg.exe in same directory as videos to be converted

    2) open file in notepad in same directory, copy & paste that code (again, I would remove the "del *.mkv" line), save it, rename .txt extension to .bat

    3) double click .bat



    If they are not in the same directory, then you have to specify full pathnames

    Another reason NOT to auto delete, is this code assumes video is track 0, 1st audio is track 1, 2nd audio is track 2. But you can have different numbering in mkv's.... e.g. -map 0:0 specifies track 0 (usually it's the video track, but not always)
    Quote Quote  
  4. Thank you for that, poisondeathray, does exactly what I wanted!

    Only problem is that it doesn't seem to enjoy the company of spaces in filenames. It works flawlessly if I have a video called "Sandwich.mkv" in the folder, but if I have "Tomato sandwich.mkv" it'll say "Tomato: no such file or directory". I tried putting some quote marks around particular parts of the command, assuming that was what it needed, but couldn't find the right part. Is there something I need to do to have it process spaces in filenames?

    Other than that, thanks a ton.
    Quote Quote  
  5. I don't know of any way around having spaces. I'm not a programmer but IIRC, DOS filenames require no spaces. Most CLI programs will "barf" if you have spaces, because the word after the space is assumed to be a new command. So use a batch file rename utility, to insert underscore or rename (search google) before running the .bat
    Quote Quote  
  6. Member
    Join Date
    Feb 2004
    Location
    United States
    Search Comp PM
    A slight modification should do the trick.

    Code:
    for %%a in (*.mkv) do ffmpeg -i "%%a" -map 0:0 -vcodec copy -map 0:1 -acodec copy -map 0:2 "%%~na".mp4
    del *.mkv
    pause
    PB
    Quote Quote  
  7. Nice autodidact, I'll have to remember that trick
    Quote Quote  
  8. Originally Posted by poisondeathray View Post

    1) place copy of ffmpeg.exe in same directory as videos to be converted
    ffmpeg.exe can be invoked from any directory / folder by adding its location (for example, C:\ffmpeg) to PATH which has worked from the DOS days through Windows 7. Just a bit of a shortcut that has been very useful to me.

    http://en.wikipedia.org/wiki/PATH_%28variable%29 has some info about PATH.
    Last edited by russell_t; 14th Jan 2012 at 18:51.
    Quote Quote  
  9. Hello

    How to Adding video into the picture with ffmpeg?

    Example:
    Image Attached Thumbnails Click image for larger version

Name:	example.png
Views:	220
Size:	731.3 KB
ID:	33325  

    Quote Quote  
  10. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    Blackwindow, Your question is off the subject of this thread (ffmpeg-script-batch-file) but since it's here... With ffmpeg easiest way is make a video of the image as long as the length of your video. To make a 30 second video from your image:

    "C:\Users\Bud\Desktop\MEGA_Trimmed_Tabbed_2\bin\De bug\ffmpeg" -loop 1 -f image2 -i "C:\Users\Bud\Desktop\img001.jpg" -c:v libx264 -t 30 "C:\Users\Bud\Desktop\img001_IMG2VID_2.mp4"

    Now overlay it with the video insertion:

    ffmpeg -i "C:\Users\Bud\Desktop\img001_IMG2VID_1.mp4" -vf "movie='C\:\\Users\\Bud\\Desktop\\birthday with audio.flv'",scale=100:75[video1];[in][video1]overlay=10:10 -crf 20 -q:v 2 "C:\Users\Bud\Desktop\img001_IMG2VID_1_OVRLY_3.mp4 "
    NO TRAILING SPACE AFTER MP4

    That will put the video in the top left corner and sized to 200x150. To move /adjust change the Scale=w:h parameter and the overlay=X:Y

    You will get:
    Click image for larger version

Name:	ScreenHunter_160 Aug. 25 23.13.jpg
Views:	1050
Size:	64.4 KB
ID:	33327

    Took 2 minutes:
    Click image for larger version

Name:	ScreenHunter_160 Aug. 25 23.18.jpg
Views:	181
Size:	85.0 KB
ID:	33328
    Last edited by Budman1; 26th Aug 2015 at 02:06.
    Quote Quote  
  11. which one is input and output video. i really dont understand your commands.

    img001.jpg its image file isnt it? Im trying to understand your commands.


    I just want to use 1 videofile and 1 images.

    you use 3 video file. so i dont understand which one is input and output.
    Last edited by blackwindow11; 25th Aug 2015 at 23:50.
    Quote Quote  
  12. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    Blackwindow11, The first string takes a JPG (img001.jpg) and turns it into a 30 second MP4 (img001_IMG2VID_2.mp4).

    The second string uses the MP4 (JPG image 30 seconds long) and overlays it with the movie (birthday with audio.flv), scaled to 200X150 and placed at overlay position 0:0 and creates the final MP4(img001_IMG2VID_1_OVRLY_2.mp4)
    Quote Quote  
  13. Originally Posted by Budman1 View Post
    Blackwindow11, The first string takes a JPG (img001.jpg) and turns it into a 30 second MP4 (img001_IMG2VID_2.mp4).

    The second string uses the MP4 (JPG image 30 seconds long) and overlays it with the movie (birthday with audio.flv), scaled to 200X150 and placed at overlay position 0:0 and creates the final MP4(img001_IMG2VID_1_OVRLY_2.mp4)
    when i try to your command. it error: invalid argument.

    why you turn it 30 second video to image? I just need images overlays with video like scaled to 200x150. I put ffmpeg file , video and image in same folder. try but getting error.
    Quote Quote  
  14. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    Blackwindow11, It would save space and time if you would have included your command and error so I could check it.??? Also I know of no way to keep an Image displayed for long enough to play the overlayed video of perhaps several minutes unless you turn the image into a constant video the same length as the overlayed one.

    I double checked the internet and only found how to overlay an image onto a video not the other way around. If I understand you correctly, you want a stable 'IMAGE' with a 'VIDEO' playing within it. correct.?? Please post the command you used to try it (cut and paste).
    Quote Quote  
  15. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    Don't ask me how to get it to stop truncating my code but the correct code should be [video1]; between the 100:75 and the [in] and no trailing space after final MP4.

    Click image for larger version

Name:	ScreenHunter_160 Aug. 26 01.46.jpg
Views:	904
Size:	35.9 KB
ID:	33331
    Quote Quote  



Similar Threads