• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

ffmpeg

Bulk FFMPEG Resize

October 31, 2022

Here’s how to resize videos and pictures using FFMPEG.

Bulk Resize Pictures

for filename in *.JPG; do 
  ffmpeg -i "$filename" -vf scale=-1:720 final/"$filename";
done

for filename in *.JPG; do ffmpeg -i "$filename" -vf scale=-1:720 final/"$filename"; done

Bulk Resize Video and Create Thumbnail

for filename in *.MP4; do 
  ffmpeg -i "$filename" -s 1080x720 -pix_fmt yuv420p -crf 18 "$filename".mp4; 
  ffmpeg -ss 00:00:00 -i "$filename" -vframes 1 "$filename".jpg;
done

for filename in *.MP4; do ffmpeg -i "$filename" -s 1080x720 -pix_fmt yuv420p -crf 18 "$filename".mp4; ffmpeg -ss 00:00:00 -i "$filename" -vframes 1 "$filename".jpg; done

Filed Under: Linux Tagged With: bulk, ffmpeg, pictures, resize, videos

FFMPEG Resize

October 25, 2022

How to resize JPEG using FFMPEG.

ffmpeg -i TREE.JPG -y -vf scale=iw*.2:ih*.2 tree.jpg

ffmpeg -i TREE.JPG -y -vf scale=iw*.2:ih*.2 tree.jpg

Another option is to set resolution.

ffmpeg -i TREE.JPG -y -vf scale=-1:720 tree.jpg

ffmpeg -i TREE.JPG -y -vf scale=-1:720 tree.jpg

How to resize video using FFMPEG.

ffmpeg -i TREE.MP4 -s 640x360 -pix_fmt yuv420p -crf 18 tree.mp4

ffmpeg -i TREE.MP4 -s 640x360 -pix_fmt yuv420p -crf 18 tree.mp4

How to create a thumbnail from a video.

ffmpeg -ss 00:00:00 -i tree.mp4 -vframes 1 tree.jpg

ffmpeg -ss 00:00:00 -i tree.mp4 -vframes 1 tree.jpg

Filed Under: Linux Tagged With: create, ffmpeg, image, resize, thumbnail, video

FFMPEG Offset Audio

June 19, 2020

If your audio is out of sync, you can fix using ffmpeg.

ffmpeg -i source.mp4 \
-i livestream.mp4 \
-map 0:0 -map 1:1 \
-acodec copy \
-vcodec copy \
-itsoffset 0.100 \
output.mp4

ffmpeg -i source.mp4 \ -i livestream.mp4 \ -map 0:0 -map 1:1 \ -acodec copy \ -vcodec copy \ -itsoffset 0.100 \ output.mp4

The ffmpeg fix is fast. A 1GB file took less than 30 seconds to run. Adjust -tsoffset until you find the sweet spot.

Filed Under: Linux Tagged With: audio, ffmpeg, offset, sync, video

FFMPEG Fix Audio Sync

June 14, 2020

If you have a video with audio sync issues, you can easily fix it using ffmpeg. It takes 2 inputs: the filename and delay: 0.100 is 100 ms or 0.1 seconds. Output file has -fixed appended to it. It’s fast. Only takes 2-3 seconds to process a 1.5 hour recording.

Here’s the script.

ffmpeg -i livestream.mp4 \
-itsoffset 0.100 \
-i livestream.mp4 \
-map 0:0 -map 1:1 \
-acodec copy \
-vcodec copy \
livestream-fixed.mp4

ffmpeg -i livestream.mp4 \ -itsoffset 0.100 \ -i livestream.mp4 \ -map 0:0 -map 1:1 \ -acodec copy \ -vcodec copy \ livestream-fixed.mp4

Filed Under: Linux Tagged With: audio, delay, ffmpeg, fix, sync

FFMPEG Convert MP3 to OGG

May 31, 2020

How to convert MP3 to OGG audio format.

ffmpeg -i in.mp3 -ar 48000 -vn -c:a libvorbis out.ogg

ffmpeg -i in.mp3 -ar 48000 -vn -c:a libvorbis out.ogg

If you have sample rate errors, use -vn.

Filed Under: Linux Tagged With: convert, ffmpeg, mp3, ogg, rate, sample

FFMPEG Convert TS to MP4

December 4, 2019

If you have video files that are formatted in MPEG-2, video files with a .m2ts extension, you can convert them to MP4 using ffmpeg.

ffmpeg -i input.ts -c:v libx264 -c:a aac output.mp4

ffmpeg -i input.ts -c:v libx264 -c:a aac output.mp4

The video is encoded using open format H.264, while audio is encoded using AAC.

Filed Under: Linux, Misc Tagged With: .m2ts, convert, ffmpeg, files, mp4, video

FFMPEG with Start Time

October 29, 2019

This is a follow up to a previous post about FFMPEG. In addition to sending a RTMP stream, you can also set a start time and duration.

Here’s how to set the start time using -ss option and -to for the duration. Video will start at 1 min 23 secs and play until 2 mins.

ffmpeg -ss 00:01:23 -i video.mp4 -to 00:02:00 -c copy -copyts cut.mp4

ffmpeg -ss 00:01:23 -i video.mp4 -to 00:02:00 -c copy -copyts cut.mp4

Here’s how to start time to start the video at 1 min 23 sec for RTMP streaming. Please note, the start time option needs to be before the input file.

ffmpeg -ss 00:01:23 \
-re -i $1 -acodec libmp3lame -ar 44100 -b:a 128k \
-pix_fmt yuv420p -profile:v baseline -s 1280x720 -bufsize 6000k \
-vb 1200k -maxrate 1500k -deinterlace -vcodec libx264           \
-preset veryfast -g 30 -r 30 -f flv                            \
-flvflags no_duration_filesize                                 \
"rtmp://username:password@yourserver:1935/live/backup"

ffmpeg -ss 00:01:23 \ -re -i $1 -acodec libmp3lame -ar 44100 -b:a 128k \ -pix_fmt yuv420p -profile:v baseline -s 1280x720 -bufsize 6000k \ -vb 1200k -maxrate 1500k -deinterlace -vcodec libx264 \ -preset veryfast -g 30 -r 30 -f flv \ -flvflags no_duration_filesize \ "rtmp://username:password@yourserver:1935/live/backup"

Filed Under: Cloud, Linux Tagged With: ffmpeg, rtmp, start time

RTMP of MP4 via FFMPEG

October 27, 2019

FFMPEG is the jack of all trades utility for both audio and video files. You can record, convert, and even live stream an audio or video file in just about any file format. In this example, I will be sending a RTMP stream of a MP4 file to a Wowza streaming server. I can easily send the same stream to YouTube, Facebook or any streaming server that accepts a RTMP source. In this example, I created simple Bash script called play.sh, with all the options needed to live stream to Wowza Streaming server.

Here are the options in play.sh.

ffmpeg -re -i $1 -acodec libmp3lame -ar 44100 -b:a 128k \
-pix_fmt yuv420p -profile:v baseline -s 1280x720 -bufsize 6000k \
-vb 1200k -maxrate 1500k -deinterlace -vcodec libx264           \
-preset veryfast -g 30 -r 30 -f flv                            \
-flvflags no_duration_filesize                                 \
"rtmp://username:password@yourserver:1935/live/backup"

ffmpeg -re -i $1 -acodec libmp3lame -ar 44100 -b:a 128k \ -pix_fmt yuv420p -profile:v baseline -s 1280x720 -bufsize 6000k \ -vb 1200k -maxrate 1500k -deinterlace -vcodec libx264 \ -preset veryfast -g 30 -r 30 -f flv \ -flvflags no_duration_filesize \ "rtmp://username:password@yourserver:1935/live/backup"

To launch, run the script.

bash play.sh filename.mp4

bash play.sh filename.mp4

Filed Under: Linux Tagged With: ffmpeg, flv, livestream, mp4, rtmp, wowza

  • Go to page 1
  • Go to page 2
  • Go to Next Page »
  • Home
  • About
  • Archives

Copyright © 2023