FORUMS: list search recent posts

Creating an if-then statement when using FFMPEG

COW Forums : FFmpeg

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Chris Zecco
Creating an if-then statement when using FFMPEG
on Apr 29, 2015 at 5:09:50 pm

Hey Everyone,

I was wondering if there was a way to create an IF-THEN statement using FFMPEG for files in a certain directory. For example, I am using FFMPEG to crunch down file sizes of videos to 50MB or lower. I would ideally like to do the following:

For file sizes in excess of 200MB:
Encode video bit rate at 1500k
Encode audio bit rate at 128k

For file sizes 100-100MB:
Encode video bit rate at 1100k
Encode audio bit rate at 128k

For file sizes less than 100MB:
Encode video bit rate at 555k
Encode audio bit rate at 128k

Is this possible? And yes, I have run tests on individual file to ensure there is no real perceptible quality loss when dropping the bit rates that low.

Any help that you could give would be amazing, and greatly appreciated.

Thanks!

- Chris

2012 Mac Pro
2x 2.4GHz Intel Xeon
24GB RAM
1GB ATI Radeon 5770

2011 Macbook Pro
2.4GHz i7
8GB RAM


Return to posts index

Jim Sustacek
Re: Creating an if-then statement when using FFMPEG
on Apr 30, 2015 at 6:44:09 pm

If the quality is good at the lowest bitrate, why not use the lowest bitrate for all files? :)

I don't know how to do any if/else switching within FFMPEG, but if you are indeed on a Mac, you could do it with BASH scripting in the Terminal, or even easier, using an Applescript. Save the following Applescript code as an application and then drag your video files onto it. (Edit the FFMPEG command to your liking, of course!)


-- Drop files on app icon
on open the_files

-- Loop through files
repeat with i from 1 to length of the_files

-- Get file path
set the_file to (item i of the_files) as text

-- Get file size in MB
set file_size to (size of (info for file the_file)) / 1000000

-- Set your FFMPEG command base
set the_command to ("/path/to/ffmpeg -i " & quoted form of (POSIX path of the_file) & " -b:a 128k -b:v ")

-- Append different video bitrates to your FFMPEG command based on file size
if file_size is greater than 200 then
set the_command to (the_command & "1500")
else if file_size is greater than 100 then
set the_command to (the_command & "1100")
else
set the_command to (the_command & "555")
end if

-- Finish your FFMPEG command
set the_command to (the_command & "k " & quoted form of (POSIX path of (the_file & ".compressed.mp4")))

-- Run your FFMPEG command
do shell script (the_command)

end repeat

end open


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]