Splitting video (mp4 or mkv) into fixed intervals as chapter markers into a single mkv file. Drag mp4 or mkv video into MKVToolNix (open source Linux, Mac, Win) into the Multiplexer | Output and choose Chapters in fixed intervals | Start Multiplexing
Chapter <NUM:2> will give Chapter 01, Chapter 02, etc. or change to <NUM:3> for Chapter 001, Chapter 002, etc. 00:15:00 or 15:00 or 15m will split audio into chapters every 15 minutes.
Chapter <NUM:2> will give Chapter 01, Chapter 02, etc. or change to <NUM:3> for Chapter 001, Chapter 002, etc. 00:15:00 or 15:00 or 15m will split audio into chapters every 15 minutes.
ffmpeg tips
ffmpeg is an open source free video encoder, muxer, audio encoder
split video into 3 min equal time interval segments split00.mp4, split01.mp4, split02.mp4, split03.mp4
ffmpeg -i input.mp4 -c copy -f segment -segment_time 3:00 -reset_timestamps 1 test%02d.mp4
-reset_timestamps 1 is critical as for each segment it recalculates the time
%02d outputs 00, 01, 02, 03, etc. change to %03 for 000, 001, 002, 003, etc.
for an hour use 1:00:00 not 60:00
ffmpeg is an open source free video encoder, muxer, audio encoder
split video into 3 min equal time interval segments split00.mp4, split01.mp4, split02.mp4, split03.mp4
ffmpeg -i input.mp4 -c copy -f segment -segment_time 3:00 -reset_timestamps 1 test%02d.mp4
-reset_timestamps 1 is critical as for each segment it recalculates the time
%02d outputs 00, 01, 02, 03, etc. change to %03 for 000, 001, 002, 003, etc.
for an hour use 1:00:00 not 60:00
ffmpeg tips
Extracts audio from a video file to an mp3 -b:a 256k - set audio bitrate (default 128kbps) -ar 44100 - Set the audio frequency of the output file. 22050, 44100, 48000 Hz. -ac 2 - Set the number of audio channels. (1 mono, 2 stereo, etc.) -vn -an -sn (skip video, audio, or subtitle stream)
Extracts audio from a video file to an mp3 -b:a 256k - set audio bitrate (default 128kbps) -ar 44100 - Set the audio frequency of the output file. 22050, 44100, 48000 Hz. -ac 2 - Set the number of audio channels. (1 mono, 2 stereo, etc.) -vn -an -sn (skip video, audio, or subtitle stream)
ffmpeg -i input.mp4 -vn output.mp3
Extract a portion from video --ss (starting time at 6 mins) -t (time duration 4m30s) OR -to (time stop)
New video clip will be from 6 mins to 10min 30seconds mark and 4 mins and 30 seconds in length.
ffmpeg -i input.mp4 -ss 6:00 -t 4:30 output.mp4
ffmpeg -i input.mp4 -ss 6:00 -to 10:30 output.mp4
Extract a portion from video --ss (starting time at 6 mins) -t (time duration 4m30s) OR -to (time stop)
New video clip will be from 6 mins to 10min 30seconds mark and 4 mins and 30 seconds in length.
ffmpeg -i input.mp4 -ss 6:00 -t 4:30 output.mp4
ffmpeg -i input.mp4 -ss 6:00 -to 10:30 output.mp4
Encode a video to x265 (hevc) --crf 28 (default) 23 is better quality but bigger file size for great movies
-crf 31 is ok for a small file size
--preset medium (default) could try fast or slow but slow isn't worth the extra encoding time. Fast is about same as medium encoding time so default I believe is perfect.
-c:v hevc (encoding to x265)
-c:v copy passthru video doesn't touch original video stream
-c:a copy passthru doesn't touch original audio stream.
-c:s copy passthru copy subtitle stream.
-c copy will copy video, audio, subtitle streams as is (passthru)
from START of video or to END of video simply don't specify anything
-crf 31 is ok for a small file size
--preset medium (default) could try fast or slow but slow isn't worth the extra encoding time. Fast is about same as medium encoding time so default I believe is perfect.
-c:v hevc (encoding to x265)
-c:v copy passthru video doesn't touch original video stream
-c:a copy passthru doesn't touch original audio stream.
-c:s copy passthru copy subtitle stream.
-c copy will copy video, audio, subtitle streams as is (passthru)
from START of video or to END of video simply don't specify anything
ffmpeg -i input.mp4 -to 5:30 output.mp4
ffmpeg -i input.mp4 -ss 6:32 output.mp4
encode clip from START of movie to 5 min 30 sec mark (to indicate START don't specify -ss)
encode clip from 6 min 32 sec mark till END of video (to indicated END time don't specify -to)
ffmpeg -i input.mp4 -ss 6:32 output.mp4
encode clip from START of movie to 5 min 30 sec mark (to indicate START don't specify -ss)
encode clip from 6 min 32 sec mark till END of video (to indicated END time don't specify -to)
This section assumes ffmpeg -i input.mkv and output.mkv or mp4, etc.
-acodec libopus (prefer opus at 32kbps for talking only and 96kbps for movies and music)
-vf scale=-2:640 will downscale 1060x720 to 640p and maintain its aspect ratio
-c:v hevc -c:a copy-acodec aac (most common one)
-acodec libopus (prefer opus at 32kbps for talking only and 96kbps for movies and music)
-c:v hevc -c:a libopus -b:a 32kresolution 3840:2160, 1920:1080, 1280:720, 854 or 720:480, 640:360, 426:240 (16:9 aspect ratios) to preserve aspect ratio while downscaling resolution or upscaling resolution use -2 value
-c:v hevc -c:a aac -b:a 64k
-vf scale=-2:640 will downscale 1060x720 to 640p and maintain its aspect ratio
To concat files together make a text file with your videos putting file before them. Put # in front of them if not used. Makes modifying list easy.
# videos.txt file '01.mp4' file '02.mp4' file '03.mp4' file '04.mp4' file '05.mp4' #file '06.mp4' #file '07.mp4'
or use this command to generate the text file
# videos.txt file '01.mp4' file '02.mp4' file '03.mp4' file '04.mp4' file '05.mp4' #file '06.mp4' #file '07.mp4'
or use this command to generate the text file
for f in *.mp4; do echo "file '$f'" >> videos.txt; doneconcat without re-encoding (make sure all have same aspect ratio, resolution, video and audio codec
ffmpeg -f concat -i videos.txt -c copy output.mp4To re-encode video and audio
ffmpeg -f concat -i videos.txt -c:v hevc -c:a libopus -b:a 64k output.mp4To replace original audio track with a new one
ffmpeg -i video.mp4 -i audio.wav -map 0:v -map 1:a -c:v hevc -vf scale="-2:720" -c:a copy -ss 1:17 -to 4:16 output.mp4sets the audio track to start at 1:17 and end at 4:16.
ffmpeg -i input.mp4 -i newaudio.opus -map 0:v -map 1:a -c:v copy -c:a copy -shortest output.mp4-shortest option sets video and audio track to the same duration determined by the shortest one.