Skip to content

Instantly share code, notes, and snippets.

@knbknb
Last active May 2, 2024 06:41
Show Gist options
  • Save knbknb/96eeb42df6b368d6830a09356f47545a to your computer and use it in GitHub Desktop.
Save knbknb/96eeb42df6b368d6830a09356f47545a to your computer and use it in GitHub Desktop.
ffmpeg hacks (various bash commands to extract audio from a video, etc.)
# You can use `ffmpeg`, a powerful tool that can be used to convert multimedia data
# from one format to another. If `ffmpeg` is not installed on your system,
# you can install it using the package manager of your Linux distribution.
ffmpeg -i input.mov -vcodec copy -acodec copy output.mp4
#In this command:
#
#- `-i input.mov` specifies the input file.
#- `-vcodec copy` and `-acodec copy` tell `ffmpeg` to copy the video and audio streams as-is, without re-encoding them.
#- `output.mp4` is the output file.
# Note: This command assumes that the codecs used in the .MOV file are compatible with the .mp4 container. If the command fails or the output file doesn't play correctly, you may need to re-encode the video and/or audio streams. Here's how you can do that:
ffmpeg -i input.mov -vcodec h264 -acodec aac output.mp4
# transcoding video to audio, reducing the file size by specifying the bitrate
# good quality (use original bitrate)
ffmpeg -i input.mp4 -vn -acodec libmp3lame -q:a 2 output.mp3
# In this command
# -i input.mp4 specifies the input file.
# -vn tells ffmpeg to disable video recording.
# -acodec libmp3lame tells ffmpeg to use the LAME MP3 encoder to encode the audio stream.
# -q:a 2 sets the audio quality. The value can be from 0 (highest quality) to 9 (lowest quality).
# A value of 2 is a good balance between size and quality.
# output.mp3 is the output file.
ffmpeg -i input.mp4 -vn -acodec libmp3lame -b:a 128k output.mp3
# a 50 min talk likely to stays belo 30 MB file size with this command
ffmpeg -i input.mp4 -vn -acodec libmp3lame -b:a 64k output.mp3
# transcoding from h.265 to mp4 format for better compatibility with other devices
ffmpeg -i input.mov -vcodec libx264 -acodec copy output.mp4
# using ffprobe tool, which is included with `ffmpeg` to get information about the video file
ffprobe -v quiet -print_format json -show_streams input.mp4 | jq ".streams[].codec_name"
# "Burning in" subtitles : encoding them directly into the video frames,
# so they can't be turned off. You can use `ffmpeg` to do this with an SRT subtitle file.
ffmpeg -i input.mp4 -vf "subtitles=input.srt" output.mp4
#In this command:
#
#- `-i input.mp4` specifies the input video file.
#- `-vf "subtitles=input.srt"` applies a video filter that adds the subtitles from `input.srt` to the video.
#- `output.mp4` is the output video file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment