VideoHelp Forum

Our website is made possible by displaying online advertisements to our visitors. Consider supporting us by disable your adblocker or Try ConvertXtoDVD and convert all your movies to DVD. Free trial ! :)
+ Reply to Thread
Results 1 to 7 of 7
Thread
  1. Member
    Join Date
    Feb 2012
    Location
    India
    Search Comp PM
    Hi,

    I have a CENTOS server with FFMPEG installed. I have around 40 directories with MP4 files in them. I'm currently re-encoding the files into an android optimized MP4 using the following command

    Code:
    $ ffmpeg -i infile.mp4 -s 432x320 -threads 4 -vcodec libx264 -flags +loop+mv4 -cmp 256 -partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -subq 5 -trellis 1 -refs 5 -bf 0 -flags2 +mixed_refs -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 27 -qmax 32 -qdiff 4 -b 384k -r 600 -acodec libfaac -ar 48000 -ab 48000 -pass 1 outfile.mp4]
    It's taking quite some time, but that's okay. I'm wondering if there is a way to convert all the MP4 files in a particular directory and place the encoded output into the same directory. I've seen a couple of threads about this. But in those threads the input format is different from the output, so I'm not sure if it'll work for me.

    Thanks
    Last edited by darklift; 3rd Feb 2012 at 05:41.
    Quote Quote  
  2. I'm a MEGA Super Moderator Baldrick's Avatar
    Join Date
    Aug 2000
    Location
    Sweden
    Search Comp PM
    Code:
    for I in *.mp4; do ffmpeg -i "$I" -s 432x320 -threads 4 -vcodec libx264 -flags +loop+mv4 -cmp 256 -partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -subq 5 -trellis 1 -refs 5 -bf 0 -flags2 +mixed_refs -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 27 -qmax 32 -qdiff 4 -b 384k -r 600 -acodec libfaac -ar 48000 -ab 48000 -pass 1 "${I%.mp4}new.mp4";done
    Try it in a folder with some test mp4 files first.
    Last edited by Baldrick; 3rd Feb 2012 at 07:12. Reason: Add done
    Quote Quote  
  3. Member
    Join Date
    Feb 2012
    Location
    India
    Search Comp PM
    Sorry, I'm kind of a linux newbie. How do I execute that? When I type all that and press enter, it takes me to the next line and stays blank. However when I press the up arrow to check the previous commands, I can see a large command that I never entered.

    I'm testing it inside a folder with 2 MP4 files.

    Thanks
    ____________________________________
    Edit: I did some searching. So, I should put the code in a .sh file in a directory and then execute it by bash name.sh, right? When doing that I get a syntax error at line 2

    Edit 2: It worked. All I had to do was add 'done' at the end of the code and then execute it.

    Thanks a lot
    Last edited by darklift; 3rd Feb 2012 at 06:50.
    Quote Quote  
  4. I'm a MEGA Super Moderator Baldrick's Avatar
    Join Date
    Aug 2000
    Location
    Sweden
    Search Comp PM
    I forgot the done after the last;

    Code:
    for I in *.mp4; do ffmpeg -i "$I" -s 432x320 -threads 4 -vcodec libx264 -flags +loop+mv4 -cmp 256 -partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -subq 5 -trellis 1 -refs 5 -bf 0 -flags2 +mixed_refs -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 27 -qmax 32 -qdiff 4 -b 384k -r 600 -acodec libfaac -ar 48000 -ab 48000 -pass 1 "${I%.mp4}new.mp4";done
    And nope, you don't have to put it in a file. You can run it directly.

    I'm running a test on centos right now,
    Code:
    for I in *.mp4; do ffmpeg -i "$I" -sameq "${I%.mp4}new.mp4"; done
    and it works fine.


    edit: I see that you have already found the solution.
    Last edited by Baldrick; 3rd Feb 2012 at 07:12.
    Quote Quote  
  5. Member
    Join Date
    Feb 2012
    Location
    India
    Search Comp PM
    Yeah, found it just before you made that post. Thanks.

    I need a little more help.

    for I in *.mp4; do ffmpeg -i "$I" -s 432x320 -threads 4 -vcodec libx264 -flags +loop+mv4 -cmp 256 -partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -subq 5 -trellis 1 -refs 5 -bf 0 -flags2 +mixed_refs -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 27 -qmax 32 -qdiff 4 -b 384k -r 600 -acodec libfaac -ar 48000 -ab 48000 -pass 1 "${I%.mp4}new.mp4";done

    How can I make the same script do the QT-faststart and an MP4Box -isma on the output file.

    Since there are around 50-100 files in one directory, it's a little time consuming to perform a QT-faststart and an MP4box isma on it one by one.

    FFMPEG converts my 01.mp4,02.mp4 into 01new.mp4,02new.mp4 etc. I take the obtained 01new.mp4 file and run this
    qt-faststart 01new.mp4 01.mp4
    MP4Box -isma 01.mp4

    Can you update the script to perform these two functions as well? Thank you
    Quote Quote  
  6. I'm a MEGA Super Moderator Baldrick's Avatar
    Join Date
    Aug 2000
    Location
    Sweden
    Search Comp PM
    Try
    Code:
    for I in *new.mp4; do qt-faststart "${I%.mp4}.mp4" "${I%.mp4}qt.mp4";done
    Code:
    for I in *newqt.mp4; do MP4Box -isma "${I%.mp4}.mp4"; done
    ANd you should end uppt 01newqt.mp4, 02newqt.mp4, etc
    Quote Quote  
  7. Member
    Join Date
    Feb 2012
    Location
    India
    Search Comp PM
    Hey, thanks a lot man. It works like charm.
    Quote Quote  



Similar Threads