Skip to content

Commit

Permalink
Update with a zero-transcoding example for AAC input files.
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxPower15 committed Apr 17, 2024
1 parent de85451 commit b89f16e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ You can find all artifacts in the "out" directory:

ls out

If you know you're operating on an input file that's 44.1KHz, you can also split up the file without transcoding. Try a command like this to test it out:

NO_TRANSCODE=1 ruby run.rb 1.0 <your-file-with-an-aac-input-stream>

On a Mac, you may want to examine out/stitched.mp4 with a visualization program. The author uses [Audacity](https://www.audacityteam.org/) for that.

open -a Audacity out/stitched.mp4

NOTE: This repo hardcodes the sample rate as 44.1KHz to simplify the demo code. But this method should work with any sample rate.
14 changes: 13 additions & 1 deletion calculations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,19 @@ def generate_command_and_directives_for_segment(input_file, index, target_start,

puts "inpoint: #{inpoint}, outpoint: #{outpoint}"

command = "ffmpeg -hide_banner -loglevel error -nostats -y -ss #{start_time_with_padding}us -t #{padded_duration}us -i #{input_file} -c:a libfdk_aac -ar 44100 -f adts out/seg#{index + 1}.aac"
command =
if ENV["NO_TRANSCODE"]
# If we know the input file is AAC and we're not changing the sample rate,
# we can create the segments without transcoding too. This works because,
# if we cut at exactly the AAC frame boundaries, then we can just slice
# out portions of the stream. Note, however, that -ss and -t flags are moved after
# the input file so they're applied after the input file is read. Without that,
# you'll get some funky output.
"ffmpeg -hide_banner -loglevel error -nostats -y -i #{input_file} -c:a copy -ss #{start_time_with_padding}us -t #{padded_duration}us -f adts out/seg#{index + 1}.aac"
else
"ffmpeg -hide_banner -loglevel error -nostats -y -ss #{start_time_with_padding}us -t #{padded_duration}us -i #{input_file} -c:a libfdk_aac -ar 44100 -f adts out/seg#{index + 1}.aac"
end

directives = [
"file 'seg#{index + 1}.aac'",
"inpoint #{inpoint}us",
Expand Down

0 comments on commit b89f16e

Please sign in to comment.