Script to test encode speeds and file sizes for libx264 encodes with a range of...
source link: https://gist.github.com/mattst/9ffee93f5053ba59275af800f0dbd654
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Script to test encode speeds and file sizes for libx264 encodes with a range of CRF values and presets · GitHub
Instantly share code, notes, and snippets.
#!/bin/bash
infile="TestClipTwoMin.mp4" datafile="TestClipTwoMinData.csv"
crfs=("18" "19" "20" "21" "22" "23" "24" "25" "26" "27") presets=("ultrafast" "superfast" "veryfast" "faster" "fast" "medium" "slow" "slower" "veryslow")
echo 'CRF,Preset,Time (Secs),Size (MB)' >> "$datafile"
for crf in "${crfs[@]}"; do for preset in "${presets[@]}"; do outfile=Out_CRF_"$crf"_Preset_"$preset".mp4 time_start=$(date +%s.%N) ffmpeg -i "$infile" -c:a copy -c:v libx264 -crf "$crf" -preset "$preset" "$outfile" time_end=$(date +%s.%N) # Dividing by 1 forces the scale to be used. time=$(echo "scale = 2; ($time_end - $time_start)/1" | bc) size_bytes=$(ls -l "$outfile" | awk '{ print $5 }') size_mb=$(echo "scale = 2; $size_bytes / 1000000" | bc) echo $crf,$preset,$time,$size_mb >> "$datafile" done done
This is incredibly helpful! I gave it a shot, but it doesn't seem to be writing the time of encoding to the CSV file. Just leaves it blank. I tried with a 1 minute clip and a 2 minute clip
Edit 1: Forgot to add i'm on MacOS Mojave
Edit 2: Made some tweaks and got Second's to appear, albeit with a little less granularity
`#!/usr/local/bin/bash
infile="test3.mov"
datafile="TestClipTwoMinData.csv"
crfs=("18" "19" "20" "21" "22" "23" "24" "25" "26" "27")
presets=("ultrafast" "superfast" "veryfast" "faster" "fast" "medium" "slow" "slower" "veryslow")
echo 'CRF,Preset,Time (Secs),Size (MB)' >> "$datafile"
for crf in "${crfs[@]}"; do
for preset in "${presets[@]}"; do
outfile=Out_CRF_"$crf"_Preset_"$preset".mp4
time_start=$(date +%s)
ffmpeg -i "$infile" -c:a aac -c:v libx264 -crf "$crf" -preset "$preset" -pix_fmt yuv420p "$outfile"
time_end=$(date +%s)
# Dividing by 1 forces the scale to be used.
time=$(((time_end-time_start) ))
size_bytes=$(ls -l "$outfile" | awk '{ print $5 }')
size_mb=$(echo "scale = 2; $size_bytes / 1000000" | bc)
echo $crf,$preset,$time,$size_mb >> "$datafile"
done
done
`
Last but not least, I think it was an issue with date in BASH on MacOS. So I wrote a work around that doesn't use date. I also added Bit Rate calculation based on putting the length in seconds of the input file at the top of the script. Pretty hackey but...
`#!/usr/local/bin/bash
infile="15s.mov"
datafile="TestClipTwoMinData.csv"
declare -i cliplength=15
crfs=("18" "19" "20" "21" "22" "23" "24" "25" "26" "27")
presets=("ultrafast" "superfast" "veryfast" "faster" "fast" "medium" "slow" "slower" "veryslow")
echo 'CRF,Preset,Time (Secs),Size (MB), Bitrate (KBps)' >> "$datafile"
for crf in "${crfs[@]}"; do
for preset in "${presets[@]}"; do
outfile=Out_CRF_"$crf"_Preset_"$preset".mp4
SECONDS=0
ffmpeg -i "$infile" -c:a aac -c:v libx264 -crf "$crf" -preset "$preset" -pix_fmt yuv420p "$outfile"
time=$SECONDS
size_bytes=$(ls -l "$outfile" | awk '{ print $5 }')
size_mb=$(echo "scale = 2; $size_bytes / 1000000" | bc)
bitrate=$(echo "scale = 2; ($size_bytes / $cliplength) / 1000" | bc)
echo $crf,$preset,$time,$size_mb,$bitrate >> "$datafile"
done
done
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Recommend
-
55
GitHub is where people build software. More than 27 million people use GitHub to discover, fork, and contribute to over 80 million projects.
-
86
README.md ...
-
48
之前在我的那个硬件网站【玩点什么】,遇到了一个 Python 的中文编码问题。大抵的问题是一个中文的 URL 的识别问题。 在访问 URL
-
51
README.md ORM IN PROGRESS Seriously, it's in progress - we don't even have foreign key support in here yet. But it's a nice...
-
55
README.md requests-async Brings support for async/await syntax to Python's fabulous requests library.
-
10
Optimized shot-based encodes for 4K: Now streaming!by Aditya Mavlankar, Liwei Guo,...
-
2
Improving our video encodes for legacy devicesby Mariana Afonso, Anush Moorthy,
-
2
POSTED ON APRIL 5, 2021 TO ML Applications, Networking & Traffic,
-
7
News Renesas Kicks-up CPU Speeds with SoCs for Entry/Mid-range Automotive Systems The demand for cost-advantaged advanced cockpit technology for mid-range and entry-level automobiles is on the rise, which prompts...
-
5
Windows 下 FFmpeg 和 LibX264 的编译和配置 标签: FFmpeg ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK