Pages

Creating the Joining Batch File

The batch file

I use this web page to create the DOS batch file that runs tsMuxeR and eac3to according to the AVCHD joining procedure described in my Joining My AVCHD Videos page. This web page works with Mozilla Firefox and Google Chrome but does not work with Internet Explorer.

Essentially, the batch file created by this web page performs the following tasks:

  1. Set up the various parameters to be used by tsMuxeR and eac3to.
  2. Set up the meta file to be used by tsMuxeR.
  3. Run eac3to to generate the joined audio file.
  4. Run tsMuxeR with the eac3to audio file to generate the joined AVCHD file.
  5. Remove some temporary files generated during the joining process.

Steps to create the batch file


  1. Enter a file name for the joined AVCHD file below:
  2. Drag and drop the AVCHD files to be joined from the AVCHD working directory to the box below:
  3. Review the AVCHD files to be joined. Repeat Step 2 if necessary. The joining sequency is listed above and is determined by the alphabetical order of the file names.
  4. Click on the button below to generate the batch code:
  5. Open Notepad from Windows:
    1. Click the Start button.
    2. Click Run.
    3. Type Notepad and press Enter.
  6. Copy the batch code to Notepad:
    1. Double-click inside the text box above to highlight all the batch code.
    2. Right-click and select Copy.
    3. Go back to Notepad.
    4. Right-click and select Paste.
  7. Save the file as AVCHD.bat:
    1. Click File from the top menu bar.
    2. Click Save As.
    3. Set "Save as type" to "All files (*.*)".
    4. Enter "AVCHD.bat" as file name.
    5. Click Save.
    6. Close Notepad.

54 comments:

Anonymous said...

Great job. Thanks for posting this.

I noticed the original separate files and the new joined file are all in the same folder. Is it possible to have these on separate physical drives and edit the batch file accordingly?

Anonymous said...

Yes, it is possible to have these files on separate locations by editing the batch code. You just need to provide the full path for each file in these two lines:

set videoFileName=
set mtsList=

Anonymous said...

bro this is cool. can u please create a downloadable program that creates the batch file, just in case you delete this blog in the future

Anonymous said...

I have got a problem. I was trying to join some MTS files from my camcorder. Some successfully joined without the audio being out of sync, but some was out of sync.

Whenever the ones that I joined got out of sync, this message was on the cmd screen, "skipping dirty PES bytes.."

Ps: the original mts files from the camcorder are showing perfectly, without any syncing problems. However when I try to join using your method, some join without having the audio sync problem, but some still gets out of sync.

I tried googling "skipping dirty pes bytes", but i didn't find a solution

DK said...

Thanks. I will try if I have time. However, I have no plan to delete this blog.

DK said...

Sorry, I have not seen this "skipping dirty PES bytes.." problem myself and do not have a solution. Hope you can find the solution somewhere else.

Uco said...

Great!

Only draging and dropping the originals in your site to create the batchfile doesn't work (instead video starts playing!) so need to create the batch file myself. Is there a setting in IE I need to change so dragging works? Win7 64; IE8

Thanks!

DK said...

Sorry, this web page does not work with Internet Explorer. You may want to view it using either Mozilla Firefox or Google Chrome. They are free and can be easily installed.

Anonymous said...

You are a genius. A stone cold genius. This works like a dream. I love you. Thankyou.

Anonymous said...

I'm still using this, and you are still a genius!

CyWa said...

I'm trying to join a BR film in a BDMV folder structure so that I get 1 large m2ts file to play with my WDTV Live.

Using your batch file, I have the following error:

H.264 stream does not contain fps field. Muxing fps 23.976

H264 warn: Force frame_mbs_only_flag division invalid detected. Cancel this flag

Bad SEI detected. SEI too short
SPS picture order 1 not supported

The process stopped prematurely and I only get a 40-60MB file. Strangely, running the batch file several times give me diff sizes. Sometimes 46B, sometimes 60MB. Once I had 120+MB.

I ran tsMuxer using the GUI (a PITA to manually add each m2ts file) and it joined it without errors. I have not tried on my wdtv live if there are sound lags or any other probs.

I'm thinking is it because of this line in the batch file:

set tsCommand1=MUXOPT --no-pcr-on-video-pid --new-audio-pes --vbr --vbv-len=500

that is causing the SEI error?

DK said...

CyWa,

Thanks for the note.

If the tsMuxeR GUI works, you may want to try to copy the MUXOPT option line from the tsMuxeR GUI to the batch file and check if this would work or not.

The other thing you may want to try is to set the fps (frame per second) parameter in the batch file:

set tsCommand3=fps=, insertSEI, contSPS, track=4113

This parameter is empty in the batch file. Normally, tsMuxeR figures out what value to use. In your case, you may want to set this parameter explicitly if you know the fps of your files.

Hope this helps.

Anonymous said...

Still using it, still thanking you...

stillwellavewarrior said...

This works better than everything else I have tried for joining m2ts files. Great actually! Thanks!

yankeesbloggen said...

This works far better than everything else I have tried for joining m2ts files. The sync problems I got when using Ts-Muxer alone are gone, that is just great! Thanks!

yankeesbloggen said...

This works far better than everything else I have tried for joining m2ts files. The sync problems I got when using Ts-Muxer alone are gone, that is just great! Thanks!

DrJ said...

When I tried this it joined the files but now the video is all strange. It runs fast for a few seconds and then pauses for a few. I got the raw files from a friend and am trying to join them together... I believe he used a SONY AVCHD Camcorder. Any help would be great.

DK said...

@DrJ,

I have tested this method only on AVCHD files from Sony camcorders. It is possible that this method may not work on raw files from other camcorders. You may want to double check the source of your files.

Anonymous said...

Thanks for the effort dude ! but I have a problem: the audio is still so out-of-sync although I followed the exact steps. The joined video is produced, but the video runs so fast while the audio runs normally. I tried setting the "fps" parameter but still nothing. I tried with 9 files and then with just 2. The videos are .mts files with 1920x1080 resolution, 25 fps, and audio bitrate is 256 kbps. what should I do ?

Virasak said...

PGS (date&time of camcorder) is missing after merged.
How can I put any parameter to keep it ?

Anonymous said...

By the way, to add more than one file simultaneously to the tsMuxeR GUI you just select the files and drag them to the "add" or "join" button ,then drop. I read about it somewhere and it works, but is there a way to use both tsMuxeR and eac3to from the txMuxeR GUI ?

DK said...

"Thanks for the effort dude ! but I have a problem: the audio is still so out-of-sync ..."

Again, I have only tested this method with AVCHD files from SONY camcorders. It may not work for AVCHD files from other camcorders. Sorry.

DK said...

"PGS (date&time of camcorder) is missing after merged.
How can I put any parameter to keep it ?"

PGS is supported by tsMuxeR but, unfortunately, is not supported by this version of the batch file generator. When I have time, I will try to look into this more.

DK said...

"By the way, to add more than one file simultaneously to the tsMuxeR GUI you just select the files and drag them to the "add" or "join" button ,then drop. I read about it somewhere and it works, but is there a way to use both tsMuxeR and eac3to from the txMuxeR GUI ?".

Thanks for the note. It is good to know. However, I don't think there is a way to invoke eac3to within the tsMuxeR GUI. That is why I need to use a batch file instead.

Anonymous said...

Great job. Thanks for posting this.

Anonymous said...

Great tool. The only solution i found. thanks.

if you want a subtitle track with recoding time/date you can use karl voss' subtitlemaker on the joined file. It works!
It uses datetimeoriginal stamp in each clip. tsmuxer maintain that meta data. fantastic.

Anonymous said...

Is there a way to set what audio track I want to use from the source file? I am dealing with German sources files that have English set to use the second audio track. The first track is in German

DK said...

Can you try the following and see if it works?

Replace this line in the batch script:

echo ".\eac3to\eac3to" %mtsList% %audioFile% > %batFile%

with

echo ".\eac3to\eac3to" %mtsList% 2: %audioFile% > %batFile%

Here, I assume you want track 2 in the source file.

Kate said...

That is amazing, is it possible to have these on separate physical drives and edit the batch file accordingly? thx.

DK said...

@Kate,

Yes, it is possible.

If the files to be joined are on a different drive, you just need to replace all ".\" with the full path name (e.g., "F:\xyz\") in the line beginning with "set mtsList" in the batch file. However, you should not replace ".\" elsewhere in the batch file.

Mark T. said...

After days of downloading apps and waiting on conversion times that turned up no sound, I found this page. Thanks. I came back today to try again from another computer and I get bat error of Source file "./00.ac3" not found. I've started over several times to no avail. Any ideas? Thanks, Mark T.

DK said...

Mark,

00.ac3 is the output merged audio file generated by eac3to. This file is deleted by the batch file after the completion of the overall merging process.

If 00.ac3 is missing before the end of the merging process, there may be something wrong with the eac3to execution. Maybe eac3to could not find the source mts files.

When using a different computer, you need to use the web script to generate a new batch file. This may solve your problem. Hope this helps.

Anonymous said...

Thank you for this page. Great job!!!

f said...

your post is so helpful, thank you for sharing.

Anonymous said...

GREAT!!!
After many hours lose finding a sw to join multiple files I found your blog an d your easy and fast solution! Thanks a lot

Anonymous said...

Great script and programme. I tried to join 700 MTS files, and received the error 00.AC3 not found...after reducing the files to 450, it worked fine.


So, for any how gets this error. Decrease the number of MTS files and join in several steps.

Anonymous said...

Did anyone find the solution for "Skipping dirty PES bytes"? Im following the setup to the tee and the batch starts then returns this in a never ending loop.

Anonymous said...

thankyou once again!

Anonymous said...

Thanks man, works like a charm.. If someone is having "audio out of sync" problem is because there is included a file video recorded without HD. It means they don't have the same resulotion.

Владимир Бырылов said...

Спасибо! Самый лучший и простой вариант работы с видеофайлами AVCHD

Anonymous said...

Thank You Very Much. Your notes really helped.

ssurajits said...

Worked wonders and workrd like a charm. Thanks for sharing..

DrPhotoOnTour said...

Hi - Many thanks for the above - I am afraid I must be thick but I am having problems. When I drag the files across o the box they do not appear? I have tried it on two machines. so it must be me. I did get a list of files in view downloads on one occasion but I usually just get a single file playing & when I run the batch file the dos flicks up very briefly and I am unable read & no joined file appears. If you could advise what stupidity I am carrying out I would be very grateful. Thanks Kevin

DK said...

DrPhotoOnTour, I suspect you were using IE to generate the batch file. Please try Chrome or Firefox.

DrPhotoOnTour said...

You are correct - Best I change browser then. Many thanks verry new to all this & going around in circles. Many thanks Kevin

DrPhotoOnTour said...

I have tried with Chrome and now I see the files and I get the MS box which says joined hit any key but I still don't get a file generated. Apologies for being a pain but still a tad confused. Thanks Kevin

Grzegorz Kłos said...

I use to use your batch file one time with success, but now I have the same problem as DrPhotoOnTour has and I no use IE :(

Anonymous said...

Hi again, I've been really stupid, realised I'd put all my mts files in their own folder within our working directory. It now works a treat :) Thanks a lot.

Anonymous said...

I'm having the same issue as DrPhotoOnTour where the batch runs but there is no joined file created?

Anonymous said...

Hi, is there a limitation to the number of file I can join using the batch file? In my case, it works fine with some 10 files. But I have 404 files to join. When starting the .bat, created with all 404 files, the process won't start and I get a message like "Windows Command Processor Doesnt Work" (sorry, I'm using a German Win10 PC. Don't know, whether the translation is correct).
Any idea, what's wrong?
I used Notepad++ to save the .bat. And in general it does work. Just not, when joining a large number of files.

Anonymous said...

Four years on and still using this, thanks!

Risto said...

Same here, i have been using it also for years. Best option available :)

Risto

Anonymous said...

Now that ea3cto handles Tru DH and DTS Master, does anyone know what to edit in the batch file to take advantage of the HD audio instead of just the core?

Anonymous said...

I've been using this for a few years and LOVE it! Thank you so much as this has been the only solution to put my files together. It's super easy and does it flawlessly. I don't know what I'd do if this page stopped working!