NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public NextPVR Other Clients Old Stuff (legacy) MVP & NMT v
« Previous 1 … 63 64 65 66 67 … 115 Next »
Maintaining aspect ratio with ffmpeg transcoding

 
  • 0 Vote(s) - 0 Average
Maintaining aspect ratio with ffmpeg transcoding
drain
Offline

Member

Posts: 91
Threads: 12
Joined: Jun 2005
#1
2006-04-03, 08:45 PM
I’ve had trouble converting avi files with aspect ratios other than 4:3 to mpeg for MVP playback. For each file I’ve had to manually figure out what top and bottom padding I need to keep the aspect ratio correct. There’s probably an easier way of doing this, but to automate the process I’ve written a wee batch file (below) that first finds the resolution of the source video from ffmpeg and then calculates the top and bottom padding required to maintain the correct aspect ratio while changing to the correct resolution for the MVP (PAL in my case).

This is fine for off-line transcoding, but the only thing I can’t figure out is how to integrate it into the real-time MVP transcode feature. And ideas?

Code:
@echo off
set inputfile=%1
set outputfile=%2
set outputxsize=720
set outputysize=576

for /f "eol=; tokens=1,2,3,4,5 delims=:,x" %%a in ('ffmpeg -i %inputfile% 2^>^&1') do (
  if "%%b"==" Video" (
    set /a inputxsize=%%d
    set /a inputysize=%%e
  )
)
echo Input video size is %inputxsize% by %inputysize%

set /a newysize=%inputysize%*%outputxsize%/%inputxsize%
echo Resized video is %outputxsize% by %newysize%

set /a padding=(%outputysize%-%newysize%)/2
echo Top and bottom padding needed is %padding%

:: Passing must be a multiple of 2
set /a padding=(%padding%/2)*2
set /a newysize=outputysize-(padding*2)
echo Corrected padding is %padding%
echo Corrected resized height is %newysize%

start "Converting" /low /wait /b ffmpeg -y -i %inputfile% -b 4000 -ac 2 -ab 224 -r 25 -s %outputxsize%x%newysize% -padtop %padding% -padbottom %padding% -f svcd %outputfile%
pBS
Offline

Posting Freak

Posts: 4,829
Threads: 182
Joined: Aug 2005
#2
2006-04-04, 04:37 AM
yea, that's a 'wee' batch file...lol! nice work...Smile
i may have an answer for ya...i made a little replacement app for ffmpeg transcoding menu in gbpvr...it's simply a replacement ffmpeg.exe that calls ffmpeg or any other app or batch with parameters and i put in a kill mechanism so if ffmpeg.exe is stopped by gbpvr it would kill the spawned process as well..
works like a charm...i even made menu items to add files to a dvd and then burn the dvd from the gbpvr menus without a plugin! Big Grin [among other things]
with it you could substitute your settings seamlessly with a proxy runner for ffmpeg....i wrote it with Auto-it so you could even edit it pretty easily and re-compile yourself Smile [it's free too]

geez,just remembered a file called Trans2MVP.bat that you can manually specify the mvp transcoder with...sillly me...lol! Big Grin [i think you also have to check the 'use ffmpeg for transcodes' checkbox in config too]

nebermind....lol
p.s. if you use mencoder in the Trans2MVP.bat i know it can auto-adjust for the MVP properly...maybe ffmpeg too..i'll check it out..
Hardware: HDHR Prime, HDPVR 1212, Raspberry pi2, VFD display w/LCDSmartie
drain
Offline

Member

Posts: 91
Threads: 12
Joined: Jun 2005
#3
2006-04-05, 06:33 AM
Thanks! I basically copied it to Trans2MVP.bat in GBPVR directory, changed the pathing a bit to find ffmpeg correctly, and it works great. I no longer have to pre-process or put up with streched recordings! My PC can keep up at 720x576 with about a 20% margin.
4zm4r3d02
Offline

Senior Member

USA
Posts: 356
Threads: 90
Joined: May 2005
#4
2006-04-24, 03:22 PM
When I try to use this to convert xvid encoded avi's, it gives a "divide by zero" error. It appears that ffmpeg is returning 0 as the x size, even though it should be 640.
Intel Core i7-4790 / 32GB RAM / Windows 10 Pro 64 bit / HDHomeRun CONNECT DUO Model: HDHR5-2US
drain
Offline

Member

Posts: 91
Threads: 12
Joined: Jun 2005
#5
2006-04-27, 08:07 PM
4zm4r3d02 Wrote:When I try to use this to convert xvid encoded avi's, it gives a "divide by zero" error. It appears that ffmpeg is returning 0 as the x size, even though it should be 640.

Ahh, yes, I found the problem a little while ago but forgot to post it, sorry. FFMpeg outputs an extra parameter, so the batch file now checks for a zero x-size and chooses the appropriate parameters if necessary. Here's by updated batch file...

Code:
@echo off
setlocal enabledelayedexpansion

set inputfile=%1
if "%2"=="" (
  set outputfile="%~dpn1.mpg"
) else (
  set outputfile=%2
)
set outputxsize=720
set outputysize=576

for /f "eol=; tokens=1,2,3,4,5,6 delims=:,x" %%a in ('THIRDP~1\ffmpeg\ffmpeg -i %inputfile% 2^>^&1') do (
  if "%%b"==" Video" (
    set /a inputxsize=%%d
    set /a inputysize=%%e
    if !inputxsize!==0 (
      set /a inputxsize=%%e
      set /a inputysize=%%f
    )
  )
)
echo Input video size is %inputxsize% by %inputysize%

set /a newysize=%inputysize%*%outputxsize%/%inputxsize%
echo Resized video is %outputxsize% by %newysize%

set /a padding=(%outputysize%-%newysize%)/2
echo Top and bottom padding needed is %padding%

set /a padding=(%padding%/2)*2
set /a newysize=outputysize-(padding*2)
echo Corrected padding is %padding%
echo Corrected resized height is %newysize%

start "Converting" /low /wait /b "Third Party\FFmpeg\ffmpeg" -y -i %inputfile% -b 4000 -ac 2 -ab 224 -r 25 -s %outputxsize%x%newysize% -padtop %padding% -padbottom %padding% -f svcd %outputfile%

endlocal
bungle
Offline

Member

Posts: 205
Threads: 26
Joined: Feb 2005
#6
2006-05-18, 07:47 PM
Thanks a lot for this. I finally got around to trying it out and it sure works great, pending some changes. I think I might have a different ffmpeg version because I had to change a couple of things. I think I had to check for "Video" with %%c and use %%f and %%g for the dimensions (going from memory). I think I also changed the dimessions. 720x576 - is that PAL? I went with 720x480, which is what I get recordings in from my 150.

Note for anyone else that is using this - when I tried and things weren't working correctly my MVP would usually just reboot. I had put this script in Trans2MVP.bat as suggested, so I just dropped to a command line and manually started a transcode with the batch file so I could see what was going on. Disable the @echo off (prepend with rem) to get more info about what's going on. Once you get it working fine with the command line you can try it from the MVP again.

Thanks again
jkressin262
Offline

Junior Member

Posts: 27
Threads: 6
Joined: May 2006
#7
2006-05-19, 02:15 PM
This looks like a really great way to keep my avi files at the right aspect ratio. However, I am having problems with this script and NTSC. Most of the AVI files I have are 640x480.

So, if I used the NTSC dimensions of 720x480, I would have the new dimensions at 720x540. It would then try to subtract 540 from 480, giving me a negative number for my border. This is obviously not right. I tried to cut the output dimensions in half (getting closer to the default output by the program) with a resolution of 360x240. The math gives me an output of 360x270. Again, the new y dimensions are larger then then original dimensions.

Am I doing something wrong? I'm getting the feeling that the only way to properly scale a 640x480 avi is to rewrite the script to place black bars on the the left and right of the image (or just let the video be a bit skewed).

Any suggestions?

Thanks,
Jonathan
drain
Offline

Member

Posts: 91
Threads: 12
Joined: Jun 2005
#8
2006-05-20, 10:22 AM
jkressin262 Wrote:However, I am having problems with this script and NTSC. Most of the AVI files I have are 640x480.

So, if I used the NTSC dimensions of 720x480, I would have the new dimensions at 720x540. It would then try to subtract 540 from 480, giving me a negative number for my border. <snip>

Am I doing something wrong? I'm getting the feeling that the only way to properly scale a 640x480 avi is to rewrite the script to place black bars on the the left and right of the image (or just let the video be a bit skewed).

Any suggestions?

Thanks,
Jonathan

Good point, I haven't come across this problem myself. I've changed the script so it now decides whether to pad or crop the video. In your situation it should now crop around 30 pixels from the top and bottom. Let us know how you get on! (Don't forget to change the outputysize for NSTC.)

BTW: I've also improved the size detection to make it a bit more robust against the problems mentioned earlier. (It now looks for the word "Video", then for a string with "x" as the 4th character as the dimensions.)

Tip: For manual conversions, I keep a shortcut to the batch file on my desktop so I can drag and drop an avi file onto the shortcut and it'll automatically generate the mpg in the same directory.

Code:
@echo off
setlocal enabledelayedexpansion

set inputfile=%1
if "%2"=="" (
  set outputfile="%~dpn1.mpg"
) else (
  set outputfile=%2
)
set outputxsize=720
set outputysize=576

for /f "eol=; tokens=1 delims=~" %%a in ('ffmpeg -i %inputfile% 2^>^&1') do (
  call :findvideosize %%a
)

echo Input video size is %inputxsize% by %inputysize%
set /a newysize=%inputysize%*%outputxsize%/%inputxsize%
if %newysize% gtr %outputysize% goto usecropping
echo Resized video is %outputxsize% by %newysize%

set /a padding=(%outputysize%-%newysize%)/2
echo Top and bottom padding needed is %padding%
set /a padding=(%padding%/2)*2
set /a newysize=outputysize-(padding*2)
echo Corrected padding is %padding%
echo Corrected resized height is %newysize%

start "Converting" /low /wait /b "ffmpeg" -y -i %inputfile% -b 4000 -ac 2 -ab 224 -r 25 -s %outputxsize%x%newysize% -padtop %padding% -padbottom %padding% -f svcd %outputfile%
goto end

:usecropping
echo Resized video is %outputxsize% by %outputysize%
set /a cropping=(%newysize%-%outputysize%)/2
echo Top and bottom cropping needed is %cropping%
set /a cropping=(%cropping%/2)*2
echo Corrected cropping is %cropping%
set /a newoutputysize = %newysize%-%cropping%*2
echo Corrected resized height is %newoutputysize%

start "Converting" /low /wait /b "ffmpeg" -y -i %inputfile% -b 4000 -ac 2 -ab 224 -r 25 -s %outputxsize%x%newysize% -croptop %cropping% -cropbottom %cropping% -f svcd %outputfile%
goto end

:end
endlocal
pause
goto :eof

:findvideosize
  :: first look for "video:"
  shift
  if "%1"=="" goto :eof
  if not "%1"=="Video:" goto findvideosize
  :findvideosizeloop
  shift
  if "%1"=="" goto :eof
  set temp=%1
  if not "%temp:~3,1%"=="x" goto findvideosizeloop
  set /a inputxsize=%temp:~0,3%
  set /a inputysize=%temp:~4,3%
goto :eof
zehd
Offline

Posting Freak

Posts: 5,119
Threads: 249
Joined: Feb 2006
#9
2006-05-20, 03:03 PM
I think this is going to be great, but I'm having some trouble...

When you said 'pathing' is there any other path needed to be set other than for ffmpeg?

I mean, the default path for ffmpeg in gbpvr is "C:\Program Files\devnz\gbpvr\Third Party\FFmpeg" so if I add:


Code:
cd "C:\Program Files\devnz\gbpvr\Third Party\FFmpeg"


to the beginning, it should be in the right location right?

Also, by default in the gbpvr folder there is also a Trans2MVP.exe. Should I do anything with that?

Also, what're the correct settings in the config/MVP page?
"use ffmpeg for transcode"
and
"use ffdshow with transcode"

And finally, have you thought about putting this on the wiki?
Frank Z
[COLOR="Gray"]
I used to ask 'why?' Now I just reinstall...
[SIZE="1"]______________________________________________
Author: ZTools: ZProcess, MVPServerChecker; UltraXMLTV Enhancer, Renamer, Manager; [/SIZE]
[/COLOR]
HtV
Offline

Posting Freak

Posts: 3,470
Threads: 46
Joined: Dec 2005
#10
2006-05-20, 04:26 PM
I guess you copied it in to trans2mvp.bat, then it should work afaik.
Selecting ffmpeg would be necessary in config. I'm not sure what ffdshow would do, you don't need it, it probably would do some extra sharpening etc, if you want that (that's my guess).
AMD Athlon 64 3000, HDD: 80, 120, 200 GB, Hauppauge 350 + 150, MVP, Asus 6000L Laptop client, Asus X50sl client,
Fritz!box 7140 modem/router, GBPVR 1.3.7.
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)

Pages (8): 1 2 3 4 5 … 8 Next »
Jump to page 


Possibly Related Threads…
Thread Author Replies Views Last Post
  MVP transcoding? dinki 12 9,273 2014-02-03, 09:35 PM
Last Post: mvallevand
  Change FFMPEG commandline Astraeus 5 3,467 2012-01-22, 06:49 PM
Last Post: mvallevand
  LiveTV & ffmpeg MVP playback stops pvruser 4 3,281 2009-02-27, 10:44 PM
Last Post: Bobins
  MVP Transcoding drbenjamin 1 1,712 2008-12-01, 06:07 AM
Last Post: mvallevand
  MVP transcoding with TS Mux daneo 0 1,451 2008-11-09, 09:20 AM
Last Post: daneo
  Transcoding files times out before they begin Zato 3 2,172 2008-10-13, 04:01 AM
Last Post: Zato
  Any way to automatically save MPG output file when transcoding jonrigg68 2 2,109 2008-06-27, 04:14 PM
Last Post: HtV
  MVP TS transcoding config.xml bug. BerkA 1 1,985 2008-06-07, 11:47 AM
Last Post: sub
  Transcoding causes pc to shut down jonrigg68 5 2,503 2008-06-07, 11:04 AM
Last Post: psycik
  MVP problems (Live TV/transcoding) natty 5 2,639 2008-04-11, 06:57 PM
Last Post: sub

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode