0

I'm a newbie to this bash scripting and I'm writing a script with ffmpeg to help my production more efficient. I think I put two questions at once and hope it won't be confused:

Here is my script:

#!/bin/bash

for file in *.mov
do
  ffmpeg  -probesize 50M -analyzeduration 100M -ss 00:00:10.00 -i "$file" -map 0:0 -map 0:1 - 
  c:a aac_at -ab 256k -ar 48000 -ac 2 -strict -2 -async 1 -c:v libx264 -crf 20 -r 24000/1001 
  -s 1920x1080 -aspect 16:9 -pix_fmt yuv420p -preset fast -partitions 
  partb8x8+partp4x4+partp8x8+parti8x8 -b-pyramid 1 -weightb 1 -8x8dct 1 -fast-pskip 1 - 
  direct-pred 1 -coder ac -trellis 1 -motion-est hex -subq 6 -me_range 16 -bf 3 -b_strategy 1 
  -sc_threshold 40 -keyint_min 24 -g 48 -qmin 3 -qmax 51 -qdiff 4 -metadata creation_time=now 
  -sn -t 00:01:00.02 -y "${file%.*}_H264_1080".mov
done

Basically what I'm tyring to do is taking a "Movie_ProRes_1080.mov" file and make it as a H264 and rename it as "Movie_H264_1080.mov". The way I work around is Export the file as "Movie" and let it added behind which is really not what I want because I need to export another file to fit this purpose. The main goal is I can use the "Movie_ProRes_1080.mov" convert it to "Movie_H264_1080".

Also, from the script, it rendered out to the same location. Would it be possible to render to a different directory? Like source at /Users/editor/source, but render out at /Users/editor/output.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189

1 Answers1

0
#!/bin/bash

for file in *.mov
do
  ffmpeg -probesize 50M -analyzeduration 100M -ss 00:00:10.00 -i "$file" -map 0:0 -map 0:1 \
  -c:a aac_at -ab 256k -ar 48000 -ac 2 -async 1 -c:v libx264 -crf 20 -r 24000/1001 \ 
  -s 1920x1080 -aspect 16:9 -pix_fmt yuv420p -preset fast -metadata creation_time=now \
  -sn -t 00:01:00.02 "output/${file%%_*}_H264_1080.mov"
done
  • If you execute this in /Users/editor/source you can simply add the output directory name to the output file. If you want to execute this from any arbitrary location then see some additional examples utilizing more parameter expansion or basename.

  • No need for declaring so many x264 options when you can just use -preset alone to deal with them. That's what -preset was made for. So you can remove everything between and including -partitions to -qdiff. -strict -2 can be removed too because you are not using an experimental component.

llogan
  • 121,796
  • 28
  • 232
  • 243
  • Cool! The output is working! Thank you so much llogan. I will try to work on -preset before, need a little bit of research. How about the replace the filename text? Do you have any idea? – Hugo Shih Oct 02 '19 at 22:05
  • @HugoShih It should already deal with the requested name change. – llogan Oct 02 '19 at 22:15