Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Announcements and Chat > General Discussion
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 25th February 2012, 21:09   #1  |  Link
linkRed
Registered User
 
Join Date: Nov 2010
Posts: 12
.bat's with FFMpeg

Heythere.
I got plenty of episodes of a show, with english and russian audio tracks. Now, the thing is, russian audiotracks are separately from containers with the video and english tracks, are lying in the folder, when I need them to be inside the containers, with the video and english track. Tracks are named after containers, they got the same names, just the extension is different.
(like 1.mkv, 1.mp3, 2.mkv, 2.mp3...)
I need to write a .bat file that would join the files with the same name into new container, using FFMpeg. When I write...
Code:
FOR %%i IN (*.mkv) DO (
ffmpeg -i %%i -i "%%~ni".mp3 -acodec copy -vcodec copy "%%~ni"1.mkv )
It does join all equally named video and .mp3's files with the same name into new container(adding "1" to it's name), but only if initial container doesn't have the audio track inside of it. If it does, then it simply muxing the audio and the video from original container, and won't add another track.

Any1, help with the code please.
linkRed is offline   Reply With Quote
Old 25th February 2012, 21:21   #2  |  Link
smok3
brontosaurusrex
 
smok3's Avatar
 
Join Date: Oct 2001
Posts: 2,392
you can either

a.
try to understand the channel -map command (which i don't) or do a two step process:

b.
1. dump video (ignore audio) to temporary file (use -an to ignore all? audio tracks)
2. merge them like you do now.

c.
use mkvmerge
__________________
certain other member
smok3 is offline   Reply With Quote
Old 25th February 2012, 22:03   #3  |  Link
linkRed
Registered User
 
Join Date: Nov 2010
Posts: 12
Option a. won't work either, unfortunately, tried. Same thing - can copy anything inside the container, but nothing on what's outside. Or I just tried it wrong.
Option c. would b 2 long. As I sad, it's not a single file, think of it as if u had 100+files=)
Option b would take two operations to be done. Somehow I believe... there should b an easier way, with only one bat file.
linkRed is offline   Reply With Quote
Old 25th February 2012, 22:29   #4  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
mkvmerge is available from the command-line:
Code:
for %%a in (*.mkv) do mkvmerge.exe -o "%%~na1.mkv" --compression -1:none "%%a" --compression -1:none "%%~na.mp3"
For ffmpeg, search "newaudio".
sneaker_ger is offline   Reply With Quote
Old 26th February 2012, 00:09   #5  |  Link
linkRed
Registered User
 
Join Date: Nov 2010
Posts: 12
Thankx for mkvmerge advie man! But I need to know about FF too.
I tried to use -newaudio but had no luck with that. I tried this
Quote:
FOR %%i IN (*.mkv) DO (
ffmpeg -i %%i -i "%%~ni".mp3 -vcodec copy -acodec copy "%%~ni"1.mkv -newaudio )
and this
Quote:
FOR %%i IN (*.mkv) DO (
ffmpeg -i %%i -vcodec copy -acodec copy -i "%%~ni".mp3 "%%~ni"1.mkv -acodec copy -newaudio )
and that
Quote:
FOR %%i IN (*.mkv) DO (
ffmpeg -i "%%~ni".mp3 -i %%i -acodec copy -vcodec copy "%%~ni"1.mkv -map 0:0 -map 1:0 )
I tried also lots of other things this night, but 4 no luck. So would u please explain to me how that works with FFMpeg?

Last edited by linkRed; 26th February 2012 at 00:14.
linkRed is offline   Reply With Quote
Old 26th February 2012, 00:52   #6  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
Had some problems there myself, stupid ffmpeg always breaking stuff or not working as documented/badly documented. Try:
Code:
for %%a in (*.mkv) do ffmpeg -i "%%a" -i "%%~na.mp3" -vcodec copy -acodec copy -map 0:0 -map 1:0 -map 0:1 "%%~na1.mkv"
sneaker_ger is offline   Reply With Quote
Old 26th February 2012, 05:34   #7  |  Link
linkRed
Registered User
 
Join Date: Nov 2010
Posts: 12
Sir, you are awesome. And brilliant. Choose what you like more.
I also find out one interesting thing, that might be useful as well.
When your code is
Quote:
for %%a in (*.avi) do (
ffmpeg -i "%%a" -i "%%~na.mp3" -vcodec copy -acodec copy -map 1:0 -map 0 "%%~na1.avi" )
You get an audio, video from container and additional audio file, and the first audio track will be the additional one.
While here
Quote:
for %%a in (*.avi) do (
ffmpeg -i "%%a" -i "%%~na.mp3" -vcodec copy -acodec copy -map 0 -map 1:0 "%%~na1.avi" )
the main track from the container will be the first one in queue.

Yet I didn't find a way to mux another audiotrack to container when it already has two of them -_-

Last edited by linkRed; 26th February 2012 at 05:43.
linkRed is offline   Reply With Quote
Old 26th February 2012, 14:41   #8  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
Quote:
Originally Posted by linkRed View Post
Yet I didn't find a way to mux another audiotrack to container when it already has two of them -_-
Well, then we'd have to add another map:
Code:
for %%a in (*.mkv) do ffmpeg -i "%%a" -i "%%~na.mp3" -vcodec copy -acodec copy -map 0:0 -map 1:0 -map 0:1 -map 0:2 "%%~na1.mkv"
right?
sneaker_ger is offline   Reply With Quote
Old 26th February 2012, 16:23   #9  |  Link
linkRed
Registered User
 
Join Date: Nov 2010
Posts: 12
Na-ah...
Quote:
[matroska @ 0000000001EFDE90] Can't write packet with unknown timestamp
av_interleaved_write_frame(): Invalid argument
and with avi...
Quote:
[avi @ 0000000001F36360] Application provided invalid, non monotonically increasing dts to muxer in stream 3: 1 >= 1
av_interleaved_write_frame(): Invalid argument
what dts?...
linkRed is offline   Reply With Quote
Old 26th February 2012, 16:36   #10  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
Decoding time stamp, which should be increasing (or at least not decreasing, though some programs require increasing), so that all frames are in the chronologically correct order.
Can't help you with that. ffmpeg can be a PITA, that's why I use mkvmerge whenever possible.
sneaker_ger is offline   Reply With Quote
Old 26th February 2012, 17:46   #11  |  Link
linkRed
Registered User
 
Join Date: Nov 2010
Posts: 12
Yeah, well then I'll have to learn the mkvmerge docs.
Thank you man. Problem solved. For now...
linkRed is offline   Reply With Quote
Old 27th February 2012, 08:47   #12  |  Link
smok3
brontosaurusrex
 
smok3's Avatar
 
Join Date: Oct 2001
Posts: 2,392
@sneaker_ger, yeah, but all that assumes that 1st track is video, which is not always the case, so -map is pretty problematic for scripting use, one way or another.
__________________
certain other member

Last edited by smok3; 27th February 2012 at 08:51.
smok3 is offline   Reply With Quote
Reply

Tags
bat, ffmpeg


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 14:25.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.