Skip to content

Instantly share code, notes, and snippets.

@spvkgn
Last active May 6, 2022 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spvkgn/02bb7f57553197fdf12651cbd51045c7 to your computer and use it in GitHub Desktop.
Save spvkgn/02bb7f57553197fdf12651cbd51045c7 to your computer and use it in GitHub Desktop.
FFmpeg tips
# Convert HLS .m3u8 playlist to MP4
ffmpeg -i playlist.m3u8 -acodec copy -vcodec copy output.mp4
# for stream with AAC audio also needs to add the bitstream filter https://ffmpeg.org/ffmpeg-bitstream-filters.html#aac_005fadtstoasc
ffmpeg -i playlist.m3u8 -acodec copy -bsf:a aac_adtstoasc -vcodec copy output.mp4
# lossless cut from URL. -ss input seeking point, -t duration
ffmpeg -ss 00:00:00 -i <URL> -t 00:00:00 -acodec copy -vcodec copy output.mp4
# get URL with youtube-dl. -to output seeing point
ffmpeg -ss 00:00:00 -i `youtube-dl -g <URL>` -t 00:00:00 -acodec copy -bsf:a aac_adtstoasc -vcodec copy -copyts -avoid_negative_ts 1 output.mp4
# create GIF using palette method https://superuser.com/a/1255109
ffmpeg -y -ss 0 -t 0.3 -i file.mp4 -filter_complex \
"fps=10,scale=320:-1:flags=lanczos[x];[x]split[x1][x2]; \
[x1]palettegen[p];[x2][p]paletteuse" output.gif
# merge video files
ffmpeg -safe 0 -f concat -i <(find . -type f -name '*' -printf "file '$PWD/%p'\n" | sort) -c copy output.mkv
# Extract audio stream
ffmpeg -i input.mkv -map 0:a:1 -c:a copy output.wav
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment