PDA

View Full Version : FPS detection


juGGaKNot
27th April 2009, 21:19
Hi

I want to "better" ( damn i hate this word ) my bat with auto detection of fps, my bat is :

@echo off

set mymovie=movie
set mypath=D:\matroska
set myvideobitrate=2000
set myfps=0:30
set myfps2=30

echo AVIsource("%mypath%\%mymovie%.avi") > "%mypath%\temp\%mymovie%.avs"
echo Crop(0,0,-0,-0) >> "%mypath%\temp\%mymovie%.avs"
echo ConvertToYV12() >> "%mypath%\temp\%mymovie%.avs"

set myfps=0:30 is needed for the mkvmerge.exe mux
set myfps2=30 is needed for the avc2avi.exe mux

How can i autodetect the audio and write it to a file ( or 2, one with 0:fps and one with fps ) and then use it for the mux ( automated )

"%mypath%\bin\mkvmerge.exe" --default-duration %myfps% -o %mypath%\%mymkv%.mkv %mypath%\temp\%mymovie%.264 %mypath%\%mymovie%.mp3
"%mypath%\bin\avc2avi.exe" -f %myfps2% -i %mypath%\temp\%mymovie%.264 -o %mypath%\temp\%mymovie%.avi
"%mypath%\bin\mkvmerge.exe" --default-duration %myfps% -o %mypath%\%myavi%.avi %mypath%\temp\%mymovie%.avi %mypath%\%mymovie%.mp3
"%mypath%\bin\MP4Box.exe" -add "%mypath%\temp\%mymovie%.264#video" -out "%mypath%\temp\%mymovie%.mp4" fps=%myfps2% -no-drop -fps %myfps2%
"%mypath%\bin\mkvmerge.exe" --default-duration %myfps% -o %mypath%\%mymp4%.mp4 "%mypath%\temp\%mymovie%.mp4" %mypath%\%mymovie%.mp3

The mux part of the bat, just added avc2avi and mp4box so it may be a bit large.

Any documentation i could read ( i see ripbot264 does it nice )

cheers

Adub
27th April 2009, 23:52
Mplayer should be able to do everything you want, from identification to extraction.

juGGaKNot
28th April 2009, 12:18
Mplayer should be able to do everything you want, from identification to extraction.

Mplayer ? isn't mplayer .. well a player ?

i'll check it out, if you could link the exact thread it would be great.

BTW i need it to be cli, no gui.

thnx, cheers.

dat720
29th April 2009, 09:44
Do some reading.... mplayer is a cli player, but it has a very handy switch called funnily enough -identify which spits out a whole heap of info regarding the video, but i suspect what you want is to advanced for batch, you may have to look at going to vbs and using regex to pull strings of data out of text.

don't be scared by vbs its not that hard, your batch can be ported to vbs with only a couple of extra lines of code.

you could also try the cli version of mediainfo but again will need vbs for advanced text manipulation

mediainfo output:
martin@martin:/media/Media/VidTools/DVD Rip$ mediainfo Top\ Gun.mkv
General
Complete name : Top Gun.mkv
Format : Matroska
File size : 1.23 GiB
Duration : 1h 45mn
Overall bit rate : 1 680 Kbps
Encoded date : UTC 2008-12-05 02:53:24
Writing application : mkvmerge v2.4.0 ('Fumbling Towards Ecstasy') built on Oct 11 2008 20:13:15
Writing library : libebml v0.7.7 + libmatroska v0.8.1

Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L5.1
Format settings, CABAC : Yes
Format settings, ReFrames : 6 frames
Muxing mode : Container profile=Unknown@5.1
Codec ID : V_MPEG4/ISO/AVC
Duration : 1h 45mn
Nominal bit rate : 1 566 Kbps
Width : 720 pixels
Height : 384 pixels
Display aspect ratio : 1.875
Frame rate : 25.000 fps
Resolution : 24 bits
Colorimetry : 4:2:0
Scan type : Progressive
Bits/(Pixel*Frame) : 0.227
Writing library : x264 core 60 r913 64848ff
Encoding settings : cabac=1 / ref=6 / deblock=1:0:0 / analyse=0x3:0x133 / me=umh / subme=7 / brdo=0 / mixed_ref=0 / me_range=64 / chroma_me=1 / trellis=2 / 8x8dct=1 / cqm=0 / deadzone=21,11 / chroma_qp_offset=0 / threads=6 / nr=0 / decimate=1 / mbaff=0 / bframes=3 / b_pyramid=1 / b_adapt=1 / b_bias=0 / direct=3 / wpredb=0 / bime=0 / keyint=250 / keyint_min=25 / scenecut=40(pre) / rc=2pass / bitrate=1566 / ratetol=1.0 / rceq='blurCplx^(1-qComp)' / qcomp=1.00 / qpmin=10 / qpmax=51 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / ip_ratio=1.40 / pb_ratio=1.30 / aq=2:1.00

Audio
ID : 2
Format : AAC
Format/Info : Advanced Audio Codec
Format version : Version 4
Format profile : Main
Codec ID : A_AAC
Duration : 1h 45mn
Channel(s) : 2 channels
Channel positions : L R
Sampling rate : 44.1 KHz
Resolution : 16 bits
Language : English

chaynik
29th April 2009, 13:38
I used the standard UNIX commands grep and sed along with ffmpeg to pull fps info from files.


fps=`ffmpeg -i "movie.avi" 2>&1 | grep "Video:"`| sed "s/.* \([1-9][0-9]\.[0-9]*\) tb(r)/\1/"`


Grep extracts the fps specific line from ffmpeg's info output, while sed filters out the framerate using regular expressions. Both tools have Windows ports so it shouldn't be hard to adapt to windows. Maybe something something like


@echo off
ffmpeg -i "movie.avi" 2>&1 | qgrep "Video:"| ssed "s/.* \([1-9][0-9]\.[0-9]*\) tb(r)/\1/" > temp.txt
set mymovie=movie
set mypath=D:\matroska
set myvideobitrate=2000
set /p myfps2= < temp.txt
set myfps=0:%myfps2%


echo AVIsource("%mypath%\%mymovie%.avi") > "%mypath%\temp\%mymovie%.avs"
echo Crop(0,0,-0,-0) >> "%mypath%\temp\%mymovie%.avs"
echo ConvertToYV12() >> "%mypath%\temp\%mymovie%.avs"

dat720
30th April 2009, 10:45
Here's a quick example of a vb script that will get the fps from mediainfo, you could even use mediainfo with qgrep and ssed with a simple modification to chaynik's script.

mediainfo.vbs
option explicit
Dim RegEx, WSH, Exec, Match
Set RegEx = New RegExp
Set WSH = CreateObject("WScript.Shell")
Set Exec = WSH.Exec("mediainfo\mediainfo.exe " & chr(34) & "Top Gun.mkv" & chr(34) & "")

RegEx.Pattern = "Frame\sRate\s*:\s*[0-9]{2,3}[.][0-9]{1,3}"
RegEx.IgnoreCase = True

For Each Match In RegEx.Execute(Exec.StdOut.ReadAll)
RegEx.Pattern = "Frame\sRate\s*:\s*"
wscript.echo regEx.Replace(Match.Value,"")
Next


You could download a copy of Visual Studio Express (its free from the msdn site) and pretty much drop this code into a program and wrap it up with a nice gui!

juGGaKNot
30th April 2009, 13:40
Do some reading.... mplayer is a cli player, but it has a very handy switch called funnily enough -identify which spits out a whole heap of info regarding the video, but i suspect what you want is to advanced for batch, you may have to look at going to vbs and using regex to pull strings of data out of text.

don't be scared by vbs its not that hard, your batch can be ported to vbs with only a couple of extra lines of code.

you could also try the cli version of mediainfo but again will need vbs for advanced text manipulation

mediainfo output:
martin@martin:/media/Media/VidTools/DVD Rip$ mediainfo Top\ Gun.mkv
General
Complete name : Top Gun.mkv
Format : Matroska
File size : 1.23 GiB
Duration : 1h 45mn
Overall bit rate : 1 680 Kbps
Encoded date : UTC 2008-12-05 02:53:24
Writing application : mkvmerge v2.4.0 ('Fumbling Towards Ecstasy') built on Oct 11 2008 20:13:15
Writing library : libebml v0.7.7 + libmatroska v0.8.1

Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L5.1
Format settings, CABAC : Yes
Format settings, ReFrames : 6 frames
Muxing mode : Container profile=Unknown@5.1
Codec ID : V_MPEG4/ISO/AVC
Duration : 1h 45mn
Nominal bit rate : 1 566 Kbps
Width : 720 pixels
Height : 384 pixels
Display aspect ratio : 1.875
Frame rate : 25.000 fps
Resolution : 24 bits
Colorimetry : 4:2:0
Scan type : Progressive
Bits/(Pixel*Frame) : 0.227
Writing library : x264 core 60 r913 64848ff
Encoding settings : cabac=1 / ref=6 / deblock=1:0:0 / analyse=0x3:0x133 / me=umh / subme=7 / brdo=0 / mixed_ref=0 / me_range=64 / chroma_me=1 / trellis=2 / 8x8dct=1 / cqm=0 / deadzone=21,11 / chroma_qp_offset=0 / threads=6 / nr=0 / decimate=1 / mbaff=0 / bframes=3 / b_pyramid=1 / b_adapt=1 / b_bias=0 / direct=3 / wpredb=0 / bime=0 / keyint=250 / keyint_min=25 / scenecut=40(pre) / rc=2pass / bitrate=1566 / ratetol=1.0 / rceq='blurCplx^(1-qComp)' / qcomp=1.00 / qpmin=10 / qpmax=51 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / ip_ratio=1.40 / pb_ratio=1.30 / aq=2:1.00

Audio
ID : 2
Format : AAC
Format/Info : Advanced Audio Codec
Format version : Version 4
Format profile : Main
Codec ID : A_AAC
Duration : 1h 45mn
Channel(s) : 2 channels
Channel positions : L R
Sampling rate : 44.1 KHz
Resolution : 16 bits
Language : English


I used the standard UNIX commands grep and sed along with ffmpeg to pull fps info from files.


fps=`ffmpeg -i "movie.avi" 2>&1 | grep "Video:"`| sed "s/.* \([1-9][0-9]\.[0-9]*\) tb(r)/\1/"`


Grep extracts the fps specific line from ffmpeg's info output, while sed filters out the framerate using regular expressions. Both tools have Windows ports so it shouldn't be hard to adapt to windows. Maybe something something like


@echo off
ffmpeg -i "movie.avi" 2>&1 | qgrep "Video:"| ssed "s/.* \([1-9][0-9]\.[0-9]*\) tb(r)/\1/" > temp.txt
set mymovie=movie
set mypath=D:\matroska
set myvideobitrate=2000
set /p myfps2= < temp.txt
set myfps=0:%myfps2%


echo AVIsource("%mypath%\%mymovie%.avi") > "%mypath%\temp\%mymovie%.avs"
echo Crop(0,0,-0,-0) >> "%mypath%\temp\%mymovie%.avs"
echo ConvertToYV12() >> "%mypath%\temp\%mymovie%.avs"


Here's a quick example of a vb script that will get the fps from mediainfo, you could even use mediainfo with qgrep and ssed with a simple modification to chaynik's script.

mediainfo.vbs
option explicit
Dim RegEx, WSH, Exec, Match
Set RegEx = New RegExp
Set WSH = CreateObject("WScript.Shell")
Set Exec = WSH.Exec("mediainfo\mediainfo.exe " & chr(34) & "Top Gun.mkv" & chr(34) & "")

RegEx.Pattern = "Frame\sRate\s*:\s*[0-9]{2,3}[.][0-9]{1,3}"
RegEx.IgnoreCase = True

For Each Match In RegEx.Execute(Exec.StdOut.ReadAll)
RegEx.Pattern = "Frame\sRate\s*:\s*"
wscript.echo regEx.Replace(Match.Value,"")
Next


You could download a copy of Visual Studio Express (its free from the msdn site) and pretty much drop this code into a program and wrap it up with a nice gui!

thnx for the information, reading now in depth.

cheers

rack04
6th May 2009, 20:47
Grep extracts the fps specific line from ffmpeg's info output, while sed filters out the framerate using regular expressions. Both tools have Windows ports so it shouldn't be hard to adapt to windows.

Maybe you could help debug the following batch script. I keep getting blank fps.txt file. Thanks.

@SET ffmpeg_PATH=C:\Program Files\MeGUI\tools\ffmpeg\ffmpeg.exe
@SET WORKING_DIRECTORY=C:\Personal\Videos

@Echo off
set /p INPUT_VIDEO="Full path to input video: "

"%ffmpeg_PATH%" -i "%INPUT_VIDEO%" 2>&1 qgrep "Video:" ssed "s/.* \([1-9][0-9]\.[0-9]*\) tb(r)/\1/">"%WORKING_DIRECTORY%\fps.txt"

juGGaKNot
6th May 2009, 21:31
Maybe you could help debug the following batch script. I keep getting blank fps.txt file. Thanks.

@SET ffmpeg_PATH=C:\Program Files\MeGUI\tools\ffmpeg\ffmpeg.exe
@SET WORKING_DIRECTORY=C:\Personal\Videos

@Echo off
set /p INPUT_VIDEO="Full path to input video: "

"%ffmpeg_PATH%" -i "%INPUT_VIDEO%" 2>&1 qgrep "Video:" ssed "s/.* \([1-9][0-9]\.[0-9]*\) tb(r)/\1/">"%WORKING_DIRECTORY%\fps.txt"

FFmpeg version SVN-r18639, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration: --enable-memalign-hack --prefix=/mingw --cross-prefix=i686-ming
w32- --cc=ccache-i686-mingw32-gcc --target-os=mingw32 --arch=i686 --cpu=i686 --e
nable-avisynth --enable-gpl --enable-zlib --enable-bzlib --enable-libgsm --enabl
e-libfaac --enable-libfaad --enable-pthreads --enable-libvorbis --enable-libtheo
ra --enable-libspeex --enable-libmp3lame --enable-libopenjpeg --enable-libxvid -
-enable-libschroedinger --enable-libx264
libavutil 50. 3. 0 / 50. 3. 0
libavcodec 52.27. 0 / 52.27. 0
libavformat 52.32. 0 / 52.32. 0
libavdevice 52. 2. 0 / 52. 2. 0
libswscale 0. 7. 1 / 0. 7. 1
built on Apr 21 2009 04:04:24, gcc: 4.2.4
Input #0, avi, from 'd:\x264\movie.avi':
Duration: 00:00:05.50, start: 0.000000, bitrate: 629165 kb/s
Stream #0.0: Video: rawvideo, bgr24, 1024x640, 40 tbr, 40 tbn, 40 tbc
Unable to find a suitable output format for 'qgrep'
ECHO is off.
Press any key to continue . . .

buzzqw
6th May 2009, 21:39
qgrep is for linux...

BHH

juGGaKNot
6th May 2009, 21:49
qgrep is for linux...

BHH

Yes, he said it has windows ports but we ...

echo AVIsource("movie.avi",audio=false) >> "movie.avs"
echo WriteFile("info.txt", "Framerate") >> ""movie.avs"
"ffmpeg.exe" -i "movie2.avs"

Works for me, rack04 adapt it for your needs.

dat720
7th May 2009, 05:12
use mediainfo for fps detection, its quicker and less likely to have mistakes like rack04's outputting to a qgrep format!

dat720
22nd May 2009, 13:02
I know this is old... but here is a very easy way to get the FPS from a video:

mediainfo video.vob --Inform="Video;%FrameRate%"

There's a whole range of inform options
--Inform="General;%Duration%"
--Inform="Video;%DisplayAspectRatio%"
--Inform="Video;%PixelAspectRatio%"
--Inform="Video;%Width%"
--Inform="Video;%Height%"
--Inform="Audio;%Format%"

You can get the whole list with the following:
mediainfo --Info-Parameters >text.txt

You can also do this:
mediainfo Die\ Hard\ 2.vob --Inform="Video;%Format%, %Duration%, %FrameRate%, %DisplayAspectRatio%, %PixelAspectRatio%, %Width%x%Height%"

Which gives this output:
MPEG Video, 3296655, 25.000, 1.778, 1.422, 720x576

You could also get tricky and do this:
mediainfo Die\ Hard\ 2.vob --Inform="Video;%Format%\n%Duration%\n%FrameRate%\n%DisplayAspectRatio%\n%PixelAspectRatio%\n%Width%x%Height%"

Which results in:
MPEG Video
3296655
25.000
1.778
1.422
720x576

Give this one a go:
mediainfo Die\ Hard\ 2.vob --Inform="Video;Format: %Format%\nDuration: %Duration%\nFPS: %FrameRate%\nBitRate: %BitRate%\nSize: %StreamSize%\nDAR: %DisplayAspectRatio%\nPAR: %PixelAspectRatio%\nResolution: %Width%x%Height%"