Page 1 of 4
Automatic Media Conversion (Ipod / Iphone)
Posted: October 21st, 2008, 7:55 am
by carphead
I've only just written this in a quick and dirty ten minute trial so please let me know if it doesn't work or if you can improve on it. I've only tested it on a 2003 and a XP box so I can't say if it'll work on anything less and I know it won't work on a Linux or Mac.
You need a copy of ffmpeg and the best source I could find for a compiled one is from Videora
here. Then put this in a .cmd file in your scripts directory...
Code: Select all
@echo off
dir /b %1\*.avi >"c:\FFmpeg\list.dir"
dir /b %1\*.mpg >>"C:\FFmpeg\list.dir"
dir /b %1\*.mkv >>"C:\FFmpeg\list.dir"
for /f %%Q in (c:\FFmpeg\list.dir) do (C:\FFmpeg\ffmpeg.exe -y -i %1\%%Q -f mp4 -vcodec libx264 -level 30 -s 480x272 -r 30000/1001 -b 768k -bt 768k -bufsize 2000k -maxrate 768k -g 250 -coder 0 -threads auto -acodec libfaac -ac 2 -ab 128k %1\%%Q.mp4)
The for to the closing .mp4) is all one line.
Then copy the ffmpeg.exe from the C:\Program Files\Red Kawa\Video Converter App\Tools\FFmpeg\ to a directory called c:\FFmpeg. That should be all. As I've said I've only just knocked this one up so it might not work for everything. Any other formats that are need can just be added to the dir /b line. And I've only tested the output with a Ipod Touch and it seems to work okay.
Re: Automatic Media Conversion (Ipod / Iphone)
Posted: October 21st, 2008, 8:50 pm
by relman
I have tried this script and it does not seem to like spaces in the file name and/or path of the file.
Get errors saying he file is not found.
Also it seems to convert everything in the folder everytime a download happens. For example if you have TV show sorting, each time you download a tv show it trys to convert any AVI in the folder.
Re: Automatic Media Conversion (Ipod / Iphone)
Posted: October 22nd, 2008, 4:25 am
by carphead
I'll look at the spaces issue. I can't say I've had that problem myself.
As for the converting everything in the directory I see why that is happening but I always keep downloads separate from my media collection. SABNZBD doesn't pass any file names across to the script only the directory. So the only way I could do this was to capture all the video files in the directory.
Re: Automatic Media Conversion (Ipod / Iphone)
Posted: October 22nd, 2008, 7:54 am
by switch
For the spaces in directory issue, you need quotes around the paths, try:
Code: Select all
@echo off
cd "%1"
dir /b *.avi >"c:\FFmpeg\list.dir"
dir /b *.mpg >>"C:\FFmpeg\list.dir"
dir /b *.mkv >>"C:\FFmpeg\list.dir"
for /f %%Q in (c:\FFmpeg\list.dir) do (C:\FFmpeg\ffmpeg.exe -y -i "%1\%%Q" -f mp4 -vcodec libx264 -level 30 -s 480x272 -r 30000/1001 -b 768k -bt 768k -bufsize 2000k -maxrate 768k -g 250 -coder 0 -threads auto -acodec libfaac -ac 2 -ab 128k "%1\%%Q.mp4")
Re: Automatic Media Conversion (Ipod / Iphone)
Posted: October 22nd, 2008, 11:48 am
by relman
Ok I have overcome my issue where it processes everything in the folder by under the TV sorting making it go into a folder called Temp. For example
where Z is my harddrive.
Z:\tv shows\show name\season 1\temp\
It will then process the file and copy it back one level to
z:\tv shows\show name\season 1\
This works great for me!
Code: Select all
@echo off
dir /b %1\*.avi >"c:\FFmpeg\list.dir"
dir /b %1\*.mpg >>"C:\FFmpeg\list.dir"
dir /b %1\*.mkv >>"C:\FFmpeg\list.dir"
for /f %%Q in (c:\FFmpeg\list.dir) do (C:\FFmpeg\ffmpeg.exe -y -i %1\%%Q -f mp4 -vcodec libx264 -level 30 -s 480x272 -r 30000/1001 -b 768k -bt 768k -bufsize 2000k -maxrate 768k -g 250 -coder 0 -threads auto -acodec libfaac -ac 2 -ab 128k %1\%%Q.mp4)
z:
cd %1
move *.avi ..\
move *.mkv ..\
move *.mpg ..\
move *.mp4 ..\
Re: Automatic Media Conversion (Ipod / Iphone)
Posted: November 10th, 2008, 6:02 am
by setTopbox
Hi,
I was trying to modify this to just convert .mkv's for my PS3 on my ubuntu server box. The PS3 doesn't seem to like high bit rate / resolution (?) mkv's for some reason. It would be nice to get them into a "PS3 workable format" right out of sab. I'm pretty new to scripting and was looking for help (am I going about it the right way?)
tia
#!/bin/sh
mkdir /tmp/FFmpeg
touch /tmp/list.dir
ls -a $1*.mkv >> /tmp/FFmpeg/list.dir
for $Q in /tmp/FFmpeg/list.dir
do /usr/bin/ffmpeg -y -i $1/$Q -f mp4 -vcodec libx264 -level 30 -s 1280x720 -r 30000/1001 -b 768k -bt 768k -bufsize 2000k -maxrate 768k -g 250 -coder 0 -threads auto -acodec libfaac -ac 2 -ab 128k $1/$Q.mp4)
cd $1
move *.mp4 ../
Re: Automatic Media Conversion (Ipod / Iphone)
Posted: November 12th, 2008, 10:00 pm
by mrgreaper
you may want to check out
http://forums.sabnzbd.org/index.php?topic=1357.0 its prety much the same thing using mencoder and can certainly be adapted
Re: Automatic Media Conversion (Ipod / Iphone)
Posted: December 15th, 2008, 5:32 pm
by doubledrat
thanks for the tip. you can auto add the result to itunes with this
Code: Select all
var fso = new ActiveXObject("Scripting.FileSystemObject");
var ITTrackKindFile = 1;
var iTunesApp = WScript.CreateObject("iTunes.Application");
var deletedTracks = 0;
var mainLibrary = iTunesApp.LibraryPlaylist;
var tracks = mainLibrary.Tracks;
var numTracks = tracks.Count;
var i;
var fname;
// Move through folder and add files.
//
var ff, fc;
ff = fso.GetFolder(WScript.Arguments.Item(0));
fc = new Enumerator(ff.files);
i = 0;
for (; !fc.atEnd(); fc.moveNext())
{
fname=fc.item().name ;
if (fname.search(/[Mm][Pp]4/) > 0)
{ mainLibrary.AddFile( fc.item() );
}
i++;
}
just do
call cscript whatever.js "
foldername"
Re: Automatic Media Conversion (Ipod / Iphone)
Posted: December 15th, 2008, 5:53 pm
by doubledrat
I spoke too soon. My iphone 3g refuses to play the resulting video from this operation. any idea why?
Re: Automatic Media Conversion (Ipod / Iphone)
Posted: December 16th, 2008, 9:49 am
by themugger
like the idea of this script but just keep getting errors - File not found a few times and no file conversion.
any ideas??? thanks
Re: Automatic Media Conversion (Ipod / Iphone)
Posted: December 16th, 2008, 4:26 pm
by NeoAndersom
I would really like to get this script to work. But I seem to be having the same problem as themugger...
Re: Automatic Media Conversion (Ipod / Iphone)
Posted: December 16th, 2008, 4:47 pm
by doubledrat
themugger wrote:
like the idea of this script but just keep getting errors - File not found a few times and no file conversion.
any ideas??? thanks
perhaps if you post the output of your script, so we can see where it's failing?
Re: Automatic Media Conversion (Ipod / Iphone)
Posted: December 17th, 2008, 3:31 am
by themugger
yeah might be helpful
managed to get a bit further and finally got the script to attempt to convert the file but it seems there is a problem with the spaces in the file name
here is the script i am using
Code: Select all
@echo off
d:
cd "%1"
dir /b *.avi >"D:\FFmpeg\list.dir"
dir /b *.mpg >>"D:\FFmpeg\list.dir"
dir /b *.mkv >>"D:\FFmpeg\list.dir"
dir /b *.mov >>"D:\FFmpeg\list.dir"
for /f %%Q in (D:\FFmpeg\list.dir) do (D:\FFmpeg\ffmpeg.exe -y -i %1\%%Qa -f mp4 -vcodec libx264 -level 30 -s 480x272 -r 30000/1001 -b 768k -bt 768k -bufsize 2000k -maxrate 768k -g 250 -coder 0 -threads auto -acodec libfaac -ac 2 -ab 128k %1\%%Q.mp4)
and the output
Code: Select all
File Not Found
File Not Found
File Not Found
FFmpeg version Sherpya-r15666, Copyright (c) 2000-2008 Fabrice Bellard, et al.
libavutil 49.12. 0 / 49.12. 0
libavcodec 52. 0. 0 / 52. 0. 0
libavformat 52.22. 1 / 52.22. 1
libavdevice 52. 1. 0 / 52. 1. 0
libswscale 0. 6. 1 / 0. 6. 1
libpostproc 51. 2. 0 / 51. 2. 0
built on Oct 22 2008 23:37:16, gcc: 4.2.5 20080919 (prerelease) [Sherpya]
D:\shares\Downloads\One Good Turn\Onea: no such file or directory
:neo the file not found errors are just becuase the script cannot find any files with a certain extension defined in the script. It seems that the files get written to the list.dir without any quotes and when they are piped out it doesnt process properly. I have tried added quotes in the script but it just errors for me.
Thanks
Re: Automatic Media Conversion (Ipod / Iphone)
Posted: December 17th, 2008, 7:40 am
by doubledrat
ok, as you say, the errors are from the dirs of files that don't exist. it's because sysoutput is being redirected, not syserror
your error is because you are not quoting the "%1\%%Qa"
and you shouldn't have the a on the end either
i.e. you need "%1\%%Q"
I would be inclined to use the code from my other suggestion, so it's more readable e.g.
Code: Select all
set name=%3
set name=%name:"=%
set dirname=%1
set dirname=%dirname:"=%
for /R %dirname% %%f in (*.avi) do D:\FFmpeg\ffmpeg.exe -y -i "%%f" -f mp4 -vcodec libx264 -level 30 -s 480x272 -r 30000/1001 -b 768k -bt 768k -bufsize 2000k -maxrate 768k -g 250 -coder 0 -threads auto -acodec libfaac -ac 2 -ab 128k "%dirname%\%name%.mp4"
for /R %dirname% %%f in (*.mpg) do D:\FFmpeg\ffmpeg.exe -y -i "%%f" -f mp4 -vcodec libx264 -level 30 -s 480x272 -r 30000/1001 -b 768k -bt 768k -bufsize 2000k -maxrate 768k -g 250 -coder 0 -threads auto -acodec libfaac -ac 2 -ab 128k "%dirname%\%name%.mp4"
etc
(the /R will find stuff even if is not in the top level folder)
you should be aware, that by stating -s 480x272, you are assuming your source is 16:9 which will make anything that is not 16:9 look odd.
I wrote something yesterday that should alleviate that, but "buyer beware", although it seems ok, it's very new code (and it's part of a greater whole, so sorry if I miss anything when I cut the relevant bits out -
Code: Select all
set dirname=%1
set dirname=%dirname:"=%
set name=%3
set name=%name:"=%
set mp4s=C:\TEMP\MP4s
REM convert to iphone format
for /R %dirname% %%f in (*.mkv) do call :iphoneit %%~sf
for /R %dirname% %%f in (*.wmv) do call :iphoneit %%~sf
for /R %dirname% %%f in (*.avi) do call :iphoneit %%~sf
for /R %dirname% %%f in (*.mov) do call :iphoneit %%~sf
GOTO :EOF
:iphoneit
REM don't repeat the exercise
IF EXIST "%mp4s%\%name%.mp4" GOTO :EOF
REM work out the aspect ratio
"f:\Program Files\MPlayer\mplayer.exe" -identify -frames 0 -vo null -ao null "%1" | find "ID_" > t.tmp
c:\uutils\sed15.exe -e "s/^/set /" -e "s/\"//g" < t.tmp > ID.bat
CALL ID.bat
DEL ID.bat
SET vw=480
SET /A ratio=%ID_VIDEO_WIDTH%*1000/%ID_VIDEO_HEIGHT%
SET /A vh=%vw%*1000/%ratio%
"F:\Program Files\ipodvidconverter\tools\ffmpeg\ffmpeg.exe" -y -i "%1" -f mp4 -vcodec mpeg4 -level 30 -s %vw%x%vh% -r 30000/1001 -b 768k -bt 768k -bufsize 2000k -maxrate 768k -g 250 -coder 0 -threads 4 -acodec libfaac -ac 2 -ab 128k "%mp4s%\%name%.mp4"
CALL cscript d:\user\itunes\addtoitunes.js "%mp4s%"
GOTO :EOF
as you can see, you will need mplayer which is freely available.
Re: Automatic Media Conversion (Ipod / Iphone)
Posted: December 17th, 2008, 6:11 pm
by themugger
Okay i am getting there and the below is working for movies that have no spaces in their name
Code: Select all
set name=%3
set name=%name:"=%
set dirname=%1
set dirname=%dirname:"=%
for /R %dirname% %%f in (*.avi) do D:\FFmpeg\ffmpeg.exe -y -i "%%f" -f mp4 -vcodec libx264 -level 30 -s 480x272 -r 30000/1001 -b 768k -bt 768k -bufsize 2000k -maxrate 768k -g 250 -coder 0 -acodec libfaac -ac 2 -ab 128k "%dirname%\%name%.mp4"
but i get the following with the a movie such as - One Good Turn
Code: Select all
c:\Program Files\SABnzbd>set name="One Good Turn"
c:\Program Files\SABnzbd>set name=One Good Turn
c:\Program Files\SABnzbd>set dirname="D:\shares\Downloads\One Good Turn"
c:\Program Files\SABnzbd>set dirname=D:\shares\Downloads\One Good Turn
Good was unexpected at this time.
c:\Program Files\SABnzbd>for /R D:\shares\Downloads\One Good Turn %f in (*.avi) do D:\FFmpeg\ffmpeg.exe -y -i "%f" -f mp4 -vcodec libx264 -level 30 -s 480x272 -r 30000/1001 -b 768k -bt 768k -bufsize 2000k -maxrate 768k -g 250 -coder 0 -acodec libfaac -ac 2 -ab 128k "D:\shares\Downloads\One Good Turn\One Good Turn.mp4"
Oh btw i had to take out the -threads as i wasn getting an error saying expecting number for threads instead of auto...