Batch merge/mux MP4 and SRT files to MKV

xnaas

So I've been searching around to an answer to this and have been able to find very many similar cases, but unable to actually find an answer to what I'm trying to do.

I took a look at these two threads in particular:

Also Google'd around and read a bunch of man pages to no avail. (Doesn't mean the answers aren't there, I just couldn't find them!)


Anyway, with that preface out of the way, here's what I'm trying to do:

I have three folders (and a billion files) of this:

  • Show Name - S##E## - Title.mp4
  • Show Name - S##E## - Title.eng.srt

I'm trying to merge every .mp4 and .srt into just Show Name - S##E## - Title.mkv with the subtitles included in the file.

The problem with the first related thread that I linked is that it just turns the .mp4 into .mkv and doesn't merge the subtitles at all.

Code:

FOR %%A IN (*.mp4) DO "C:\Program Files\MKVToolNix\mkvmerge.exe" -o "%%~nA.mkv" "%%~A"

This creates the .mkv file, but doesn't include the subtitles. If I try to add "%%~dpnA.srt" or anything after "%%~A", I get a message saying: Error: The file 'C:\Users\xnaas\Desktop\test\Show Name - S##E## - Title.srt' could not be opened for reading: open file error. and similar. I geuss my biggest confusion here is I don't know what any of what I'm typing is doing. What is a ~ or nA doing?

The problem with the second link is that I don't know how to adapt it to be in batch form because I'm not sure how to do that with ffmpeg at all. I assume it's just another for loop, but I'm not all that familiar with it.

This is the only script I've used for ffmpeg (Linux now vs Windows above) before:

for f in *.mkv; do ffmpeg -i "$f" -c:v libx264 -preset medium -crf 18 -c:a copy "encoded/${f%.mkv}.mkv"; done

I'm sure it could probably be adapted, but I'm not sure how.

for f in *.mp4; do ffmpeg -i "$f" -c copy "test/${f%}.mkv"; done

That's the best I could come up with after a long while tinkering with it, but this obviously doesn't bring in the subtitle files and it names everything .mp4.mkv as well.


Sorry for the massive wall of crap up there. I look forward to any assistance/insight anyone can offer. Thank you!

heavyd

I'll try to explain how the batch parameters that are given here are being applied to the script you gave.

The basic parameter in the FOR loop is %%A. The %%A is modified in the following ways:

  • "%%~nA.mkv" is removing the quotes (~) and using just the filename (n).
  • "%%~A" is just removing any quotes (~)

I think your final command should end up as:

FOR %%A IN (*.mp4) DO "C:\Program Files\MKVToolNix\mkvmerge.exe" -o "%%~nA.mkv" "%%~A" "%%~nA.eng.srt"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Batch merge/mux .srt with .mkv files

From Dev

FFmpeg : mp4 and multiple srt into mkv

From Dev

how to Concatenate mp4 or mkv files using avconv

From Dev

How can I convert .mp4 files and .srt file to images based on subtitle's timeline?

From Dev

Multimedia files .mp4, .mkv, .avi, .flac. Having a ( ? ) question mark

From Dev

How to convert mp4 to mkv?

From Dev

How to convert mp4 to mkv?

From Dev

Hardcoding FFMPEG subtitles on MP4 / MKV

From Dev

Recursively convert mkv to mp4 with avconv

From Dev

MKV to MP4 container solution

From Dev

Help with MKV to MP4 Remux script

From Dev

Videos (MKV,MP4) slow

From Dev

How to enable thumbnail previews for my non-standard (mp4 avi mov mkv) video files in Windows 8?

From Dev

bulk/batch convert mp4 and m4v files to webm via command line?

From Dev

bulk/batch convert mp4 and m4v files to webm via command line?

From Dev

How to convert mkv movies to mp4 for streaming to XBox 360

From Dev

When converting mkv to mp4, the audio is lost

From Dev

Decoding mp4/mkv using FFMPEG fails

From Dev

Trying to convert MKV to MP4 with avconv, failing

From Dev

How to extract subtitles from MP4 and MKV movies

From Dev

Trying to convert MKV to MP4 with avconv, failing

From Dev

vlc cannot play mkv and mp4 formats

From Dev

Use FFMPEG To Convert .MKV to .MP4 With Conversion Settings

From Dev

ffmpeg cut, encode MKV to MP4, and burn subtitles

From Dev

How to convert .mkv file into .mp4 file losslessly?

From Dev

FFMPEG - Convert MKV to MP4 with all streams (subtitles) and watermark

From Dev

Recovering maybe damaged subtitles from mkv to convert into mp4

From Dev

How to easily convert an MKV video to an MP4

From Dev

how can I batch extract audio from mp4 files with ffmpeg without decompression (automatic audio codec detection)?

Related Related

  1. 1

    Batch merge/mux .srt with .mkv files

  2. 2

    FFmpeg : mp4 and multiple srt into mkv

  3. 3

    how to Concatenate mp4 or mkv files using avconv

  4. 4

    How can I convert .mp4 files and .srt file to images based on subtitle's timeline?

  5. 5

    Multimedia files .mp4, .mkv, .avi, .flac. Having a ( ? ) question mark

  6. 6

    How to convert mp4 to mkv?

  7. 7

    How to convert mp4 to mkv?

  8. 8

    Hardcoding FFMPEG subtitles on MP4 / MKV

  9. 9

    Recursively convert mkv to mp4 with avconv

  10. 10

    MKV to MP4 container solution

  11. 11

    Help with MKV to MP4 Remux script

  12. 12

    Videos (MKV,MP4) slow

  13. 13

    How to enable thumbnail previews for my non-standard (mp4 avi mov mkv) video files in Windows 8?

  14. 14

    bulk/batch convert mp4 and m4v files to webm via command line?

  15. 15

    bulk/batch convert mp4 and m4v files to webm via command line?

  16. 16

    How to convert mkv movies to mp4 for streaming to XBox 360

  17. 17

    When converting mkv to mp4, the audio is lost

  18. 18

    Decoding mp4/mkv using FFMPEG fails

  19. 19

    Trying to convert MKV to MP4 with avconv, failing

  20. 20

    How to extract subtitles from MP4 and MKV movies

  21. 21

    Trying to convert MKV to MP4 with avconv, failing

  22. 22

    vlc cannot play mkv and mp4 formats

  23. 23

    Use FFMPEG To Convert .MKV to .MP4 With Conversion Settings

  24. 24

    ffmpeg cut, encode MKV to MP4, and burn subtitles

  25. 25

    How to convert .mkv file into .mp4 file losslessly?

  26. 26

    FFMPEG - Convert MKV to MP4 with all streams (subtitles) and watermark

  27. 27

    Recovering maybe damaged subtitles from mkv to convert into mp4

  28. 28

    How to easily convert an MKV video to an MP4

  29. 29

    how can I batch extract audio from mp4 files with ffmpeg without decompression (automatic audio codec detection)?

HotTag

Archive