How to run multiple mpg video files conversion to mkv files from bat file

Started by avilon, September 19, 2020, 08:35:07 AM

Previous topic - Next topic

avilon

What is best way to convert folder of mpg files to mkv?

All web search support results are not easy to understand. Most instructions likely are for older Avidemux versions or there is no explanation of parameter.
Can't find this either from Avidemux GUI.
 
Single file conversion test with default settings is successful.
How does this script looks like?
Can it be run as bat file?

1. open mpg video
2. set output to mkv
3. "save"

 .... repeated for each single next file

Avidemux 2.7.5
Windows 7

Urik

If you're talking about just re-wrapping (without re-encoding), the fastest way would be via a batch script and ffmpeg. Here's a simple barebone batch script:
@echo off
for %%A in (%*) do ( ffmpeg -i "%%~A" -c copy "%%~dpnA.mkv")
You'll need ffmpeg "installed" as system command (google it), or otherwise you'll need to change ffmpeg to full path like C:\ffmpeg\big\ffmpeg.exe or wherever the exe is located.
This is for files, not folders. Drag & drop files onto .bat itself, or you can put the .bat (or shortcut) into Explorer SendTo menu to give it files via "Send To" context menu.

Here's a more advanced example of the script, with variables for path/extension, optional output folder entry, etc: https://pastebin.com/hxQZJvCx

If you're looking for simpler GUI-based way, Shutter Encoder could be an option (it's free too).

@eumagga0x2a on a slightly related note, I think I just realized that if I save a .py Avidemux project with certain settings, remove input file reference and put it into plugins\autoScripts , I can then use it as a quick preset?

eumagga0x2a

Quote from: Urik on September 19, 2020, 10:53:54 AMI think I just realized that if I save a .py Avidemux project with certain settings, remove input file reference and put it into plugins\autoScripts , I can then use it as a quick preset?

Sure, this is how it is supposed to work.

@avilon:

As Urik already wrote, the first question would be what do you mean by "conversion"?

Even if you only repackage, it is important to know what kind of mpg the source is. Is it MPEG-PS with MPEG-2 video? Is it MPEG-PS with navigation data as required for DVD? Do files include DVD subtitles which you don't want to lose? (If yes, Avidemux is not the tool for this task as it doesn't support subtitle tracks.)

Are there multiple audio tracks which should be kept? Then the suggested ffmpeg command needs to be adjusted else it will by default drop all audio tracks except of the first one.

Without questions: please update your Avidemux, it is old and unsupported. I would recommend going straight for the latest pre-2.7.7 nightly:

https://avidemux.org/nightly/vsWin64/ (VC++ builds)

or

https://avidemux.org/nightly/win64/ (MinGW builds)

eumagga0x2a

Quote from: eumagga0x2a on September 19, 2020, 01:18:56 PM
Quote from: UrikI think I just realized that if I save a .py Avidemux project with certain settings, remove input file reference and put it into plugins\autoScripts , I can then use it as a quick preset?

Sure, this is how it is supposed to work.

Actually, it belongs into the "custom" subdirectory of Avidemux profile.

eumagga0x2a

A note regarding remuxing mpg (MPEG-PS?) into mkv with ffmpeg in stream copy mode: one should keep in mind that libavformat in ffmpeg will abort saving as mkv if it encounters a frame without PTS which is often the case in MPEG-PS and -TS. Avidemux therefore tries to create valid timestamps for all frames. ffmpeg's genpts often doesn't help here.

Urik

Quote from: eumagga0x2a on September 19, 2020, 02:04:48 PMActually, it belongs into the "custom" subdirectory of Avidemux profile.
Oh, that makes sense now! Before I was convinced the "custom" menu is just broken.

Quote from: eumagga0x2aAre there multiple audio tracks which should be kept?
Forgot about that. I assumed they want to repackage some very old camera footage. I once had a camera that shot 480p .mpg videos in some old mpeg variant.

avilon

It takes a while to decrypt all replies.
Thanks :-)
It's 20 yrs old mpg footage which fails to play normally (no jump or FF) until repacked into mkv with Avidemux.
Repacking 20 minutes takes less then minute, so it's not re encoding.
Just a 3 steps as listed in initial posting.
There is single audio an no subtitles.

From older tutorials I have understood that easiest might be a bat file, except that I don't know exact name of formats and parameters - Avidemux 3 step doesn't need it.

Thanks for any ideas.



eumagga0x2a

I guess that https://avidemux.org/smif/index.php?msg=88111 does pretty exactly what you want. You would need to replace "mp4" with "mpg" and eventually tweak the line

adm.setContainer("MKV", "forceDisplayWidth=False", "displayWidth=1280", "displayAspectRatio=0")
to match the properties of the source mpg files (most MPEG-2 videos are anamorphic, so that you would need to force a particular aspect ratio for them to be displayed correctly, e.g.

adm.setContainer("MKV", "forceDisplayWidth=False", "displayWidth=1280", "displayAspectRatio=1")
for the standard 4:3 display aspect ratio).

avilon

i found a very simple script bat file content which seems to work - so far no problems found.

set avidemux="C:\Program Files\Avidemux 2.7 VC++ 64bits\avidemux.exe"
set videocodec=Xvid
set audiocodec=MP3
for %%f in (*.mpg) do %avidemux% --video-codec %videocodec% --audio-codec %audiocodec% --force-alt-h264 --load "%%f" --save "%%f.avi" --quit.

Thanks for everyone to support.

eumagga0x2a

This batch script works for you only because it is so outdated that harmful (not matching your declared goal) options are invalid and thus ignored. Additionally, the Avidemux command line in the script doesn't specify output format so that you probably end up with Matroska (MP4 is also possible, if you use the latest nightly) files with .avi filename extension.

The list of errors:

1. Video codec "Xvid" doesn't exist in Avidemux --> ignored

2. Audio codec "MP3" doesn't exist --> ignored

3. The option "--force-alt-h264" (nonsensical in this context) doesn't exist --> ignored

4. The option "--load" must come first (it doesn't in the script), this is an important error which can have unintended consequences as loading a video may reset everything to default values if Avidemux is configured so.

5. The option "--output-format", necessary to specify the desired muxer, is missing, so the current setting, whatever it is, is used.

set avidemux="C:\Program Files\Avidemux 2.7 VC++ 64bits\avidemux.exe"
set videocodec=Copy
set audiocodec=Copy
for %%f in (*.mpg) do %avidemux% --load "%%f" --output-format MKV --video-codec %videocodec% --audio-codec %audiocodec% --save "%%~dpnf.mkv" --quit

The solution using internal python scripting avoids repeated closing and opening of Avidemux and can take care of important details like display aspect ratio.