FORUMS: list search recent posts

Batch conversion with conditions

COW Forums : Compression Techniques

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Kirk Smith
Batch conversion with conditions
on Aug 17, 2010 at 7:59:52 pm

I have a folder full of videos of various different formats and resolutions. I provide these videos for download from my site (they are my creation or free-use.) I'm adding a mobile section to my site where i'd like to provide these videos in a mobile-streamable format. I know the format that I want, the resolution, bitrate, and audio bitrate, so that's not an issue. The issue is the fact that these videos are not all the same resolution to start with. Some are smaller than the resolution I want to use for my conversion, some are the same size, and some are larger, some have different aspect rations, and they're all sorts of different formats.

I need a way to batch-convert these using ffmpeg to my specific format, but I don't want to stretch the videos if they're smaller than my format, I only want to shrink the ones that are larger. I still need to convert the other ones to the right format, just without resizing those specifically.

I'm using a Linux Shell on my server (shared hosting) to perform this. I've used this command:

for I in *.[ext]; do ffmpeg -i I -size WxH -b ##k -ab ##k converted/I.[new ext]; done

To good effect, but that's when all the videos are of the same starting resolution. Any ideas on how I might ignore the size option for videos that are already smaller than the required size, only resizing the ones larger, but converting them all?

Return to posts index

Michael Rampe
Re: Batch conversion with conditions
on Aug 18, 2010 at 7:30:24 am

I have recently been working on a shell script that detects size and aspect ratio amongst other things. This example might give you some ideas of writing your own shell script.

1. perform a header read of the input file and write to a file
2. use grep/sed/awk combination to isolate the required data
3. assign required data to variables
4. use variables to build the FFmpeg command line
5. run the FFmpeg command line

(This will happen anyway with FFmpeg if not specifying size but should give you an idea of the method)

1. Use "ffmpeg -i inputfile 2> data.txt"
This will write the console text output to a file which will contain the stream data including size

2&3. This can be a bit tricky but what I use as an example is:
INPUTWIDTH=$(cat data.txt | grep "[0-9]x[0-9]" | sed 's/x/ /g' | awk '{ print $1 }')
INPUTHEIGHT=$(cat data.txt | grep "[0-9]x[0-9]" | sed 's/x/ /g' | awk '{ print $2 }')

4&5. Once the variables are set:
ffmpeg -i inputfile [encoding parameters] -s $INPUTWIDTH\x$INPUTHEIGHT outputfile.mp4

Although this doesn't directly solve your problem, it should be possible to run and "if" scenario based on the size variables to allow the script to make the right decision to encode or resize based on input size.

I will have a go on the logic when I get the chance.


"half-way to world domination A.K.A. the belligerent blue bike shed"

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 All Rights Reserved