Skip to content

Instantly share code, notes, and snippets.

@Andrey2G
Last active May 3, 2024 11:26
Show Gist options
  • Star 50 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save Andrey2G/78d42b5c87850f8fbadd0b670b0e6924 to your computer and use it in GitHub Desktop.
Save Andrey2G/78d42b5c87850f8fbadd0b670b0e6924 to your computer and use it in GitHub Desktop.
Video Encoding with multiple resolutions
ffmpeg -i "c:/videos/sample.mp4
-map 0:v:0 -map 0:a:0 -map 0:v:0 -map 0:a:0 -map 0:v:0 -map 0:a:0
-c:v libx264 -crf 22 -c:a aac -ar 48000
-filter:v:0 scale=w=480:h=360 -maxrate:v:0 600k -b:a:0 64k
-filter:v:1 scale=w=640:h=480 -maxrate:v:1 900k -b:a:1 128k
-filter:v:2 scale=w=1280:h=720 -maxrate:v:2 900k -b:a:2 128k
-var_stream_map "v:0,a:0,name:360p v:1,a:1,name:480p v:2,a:2,name:720p"
-preset slow -hls_list_size 0 -threads 0 -f hls -hls_playlist_type event -hls_time 3
-hls_flags independent_segments -master_pl_name "name-pl.m3u8"
"c:/videos/encoded/name-%v.m3u8"
@winlinvip
Copy link

It's useful, and bellow is for live streaming, to covert RTMP to HLS:

ffmpeg -f flv -i "rtmp://server/live/livestream" \
  -map 0:v:0 -map 0:a:0 -map 0:v:0 -map 0:a:0 -map 0:v:0 -map 0:a:0 \
  -c:v libx264 -crf 22 -c:a aac -ar 48000 \
  -filter:v:0 scale=w=480:h=360  -maxrate:v:0 600k -b:a:0 500k \
  -filter:v:1 scale=w=640:h=480  -maxrate:v:1 1500k -b:a:1 1000k \
  -filter:v:2 scale=w=1280:h=720 -maxrate:v:2 3000k -b:a:2 2000k \
  -var_stream_map "v:0,a:0,name:360p v:1,a:1,name:480p v:2,a:2,name:720p" \
  -preset fast -hls_list_size 10 -threads 0 -f hls \
  -hls_time 3 -hls_flags independent_segments \
  -master_pl_name "livestream.m3u8" \
  -y "livestream-%v.m3u8"

For detail please read here

@gulshan-dev123789
Copy link

gulshan-dev123789 commented Mar 21, 2024

is there any way i can stream the output directly to s3 bucket not in my local ??
it will really helpful.

@gulshan-dev123789
Copy link

stderr: More than 1 variant streams are present, %v is expected either in the filename or in the sub-directory name of file pipe:
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument

encounter this error

@Andrey2G
Copy link
Author

is there any way i can stream the output directly to s3 bucket not in my local ?? it will really helpful.

I would suggest to use Amazon Elastic Transcoder in this case.

  • setup/configure preset
  • create a pipeline
  • upload source video to your S3 bucket
  • start the job for selected pipeline and that source video file

https://docs.aws.amazon.com/elastictranscoder/latest/developerguide/getting-started.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment