FFmpeg: How to split video effectively?

I want to split a large avi video into two smaller consecutive videos. I am using ffmpeg.

One way is to run ffmpeg two times:

ffmpeg -i input.avi -vcodec copy -acodec copy -ss 00:00:00 -t 00:30:00 output1.avi ffmpeg -i input.avi -vcodec copy -acodec copy -ss 00:30:00 -t 00:30:00 output2.avi 

But, according to the ffmpeg man page, I can make several files with one input file using only one line:

 ffmpeg -i input.avi -vcodec copy -acodec copy -ss 00:00:00 -t 00:30:00 output1.avi \ -vcodec copy -acodec copy -ss 00:30:00 -t 00:30:00 output2.avi 

My question is, does the later approach support computation time and memory?

+87
ffmpeg
Apr 13 2018-11-11T00:
source share
10 answers

The ffmpeg link links to this page in the "How to effectively split video" section. I am not convinced that this page answers this question, so I did it as @AlcubierreDrive ...

 echo "Two commands" time ffmpeg -v quiet -y -i input.ts -vcodec copy -acodec copy -ss 00:00:00 -t 00:30:00 -sn test1.mkv time ffmpeg -v quiet -y -i input.ts -vcodec copy -acodec copy -ss 00:30:00 -t 01:00:00 -sn test2.mkv echo "One command" time ffmpeg -v quiet -y -i input.ts -vcodec copy -acodec copy -ss 00:00:00 -t 00:30:00 \ -sn test3.mkv -vcodec copy -acodec copy -ss 00:30:00 -t 01:00:00 -sn test4.mkv 

What exits ...

 Two commands real 0m16.201s user 0m1.830s sys 0m1.301s real 0m43.621s user 0m4.943s sys 0m2.908s One command real 0m59.410s user 0m5.577s sys 0m3.939s 

I tested the SD and HD file, after several runs and a little math.

 Two commands SD 0m53.94 #2 wins One command SD 0m49.63 Two commands SD 0m55.00 One command SD 0m52.26 #1 wins Two commands SD 0m58.60 #2 wins One command SD 0m58.61 Two commands SD 0m54.60 One command SD 0m50.51 #1 wins Two commands SD 0m53.94 One command SD 0m49.63 #1 wins Two commands SD 0m55.00 One command SD 0m52.26 #1 wins Two commands SD 0m58.71 One command SD 0m58.61 #1 wins Two commands SD 0m54.63 One command SD 0m50.51 #1 wins Two commands SD 1m6.67s #2 wins One command SD 1m20.18 Two commands SD 1m7.67 One command SD 1m6.72 #1 wins Two commands SD 1m4.92 One command SD 1m2.24 #1 wins Two commands SD 1m1.73 One command SD 0m59.72 #1 wins Two commands HD 4m23.20 One command HD 3m40.02 #1 wins Two commands SD 1m1.30 One command SD 0m59.59 #1 wins Two commands HD 3m47.89 One command HD 3m29.59 #1 wins Two commands SD 0m59.82 One command SD 0m59.41 #1 wins Two commands HD 3m51.18 One command HD 3m30.79 #1 wins 

SD file = DVB transport stream 1.35GB
HD file = 3.14GB DVB Transport Stream

Conclusion

The only command is better if you are processing HD, it is consistent with the comments of the manual on using -ss after the input file for "slow search". SD files have a slight difference.

The two versions of the commands should be faster by adding another -ss in front of the input file for a quick search, followed by a more accurate slow search.

+69
Oct 10 '13 at 15:51
source share

Here's a useful script, it helps you automatically split: A script to split the video with ffmpeg

 #!/bin/bash # Written by Alexis Bezverkhyy <alexis@grapsus.net> in 2011 # This is free and unencumbered software released into the public domain. # For more information, please refer to <http://unlicense.org/> function usage {    echo "Usage : ffsplit.sh input.file chunk-duration [output-filename-format]"    echo -e "\t - input file may be any kind of file reconginzed by ffmpeg"    echo -e "\t - chunk duration must be in seconds"    echo -e "\t - output filename format must be printf-like, for example myvideo-part-%04d.avi"    echo -e "\t - if no output filename format is given, it will be computed\ automatically from input filename" } IN_FILE="$1" OUT_FILE_FORMAT="$3" typeset -i CHUNK_LEN CHUNK_LEN="$2" DURATION_HMS=$(ffmpeg -i "$IN_FILE" 2>&1 | grep Duration | cut -f 4 -d ' ') DURATION_H=$(echo "$DURATION_HMS" | cut -d ':' -f 1) DURATION_M=$(echo "$DURATION_HMS" | cut -d ':' -f 2) DURATION_S=$(echo "$DURATION_HMS" | cut -d ':' -f 3 | cut -d '.' -f 1) let "DURATION = ( DURATION_H * 60 + DURATION_M ) * 60 + DURATION_S" if [ "$DURATION" = '0' ] ; then    echo "Invalid input video"    usage    exit 1 fi if [ "$CHUNK_LEN" = "0" ] ; then    echo "Invalid chunk size"    usage    exit 2 fi if [ -z "$OUT_FILE_FORMAT" ] ; then    FILE_EXT=$(echo "$IN_FILE" | sed 's/^.*\.\([a-zA-Z0-9]\+\)$/\1/')    FILE_NAME=$(echo "$IN_FILE" | sed 's/^\(.*\)\.[a-zA-Z0-9]\+$/\1/')    OUT_FILE_FORMAT="${FILE_NAME}-%03d.${FILE_EXT}"    echo "Using default output file format : $OUT_FILE_FORMAT" fi N='1' OFFSET='0' let 'N_FILES = DURATION / CHUNK_LEN + 1' while [ "$OFFSET" -lt "$DURATION" ] ; do    OUT_FILE=$(printf "$OUT_FILE_FORMAT" "$N")    echo "writing $OUT_FILE ($N/$N_FILES)..."    ffmpeg -i "$IN_FILE" -vcodec copy -acodec copy -ss "$OFFSET" -t "$CHUNK_LEN" "$OUT_FILE"    let "N = N + 1"    let "OFFSET = OFFSET + CHUNK_LEN" done 
+16
Nov 08
source share

http://ffmpeg.org/trac/ffmpeg/wiki/Seeking%20with%20FFmpeg may also be useful to you. In addition, ffmpeg has a segmented multiplexer that can work.

In any case, I assume that combining them into one team will save time.

+5
Oct. 17 '12 at 17:17
source share

In my experience, do not use ffmpeg to split / join. MP4Box, faster and lighter than ffmpeg. Please, try. For example, if you want to split a 1400mb MP4 file into two parts into 700 MB, you can use the following cmdl: MP4Box -splits 716800 input.mp4 for example, to concatenate two files that you can use:

 MP4Box -cat file1.mp4 -cat file2.mp4 output.mp4 

Or, if you need to split by time, use -splitx StartTime:EndTime : -splitx StartTime:EndTime :

MP4Box -add input.mp4 -splitx 0:15 -new split.mp4

+5
Aug 10 '16 at 22:05
source share

Here is a simple bat file for Windows to split the input file into 50 parts. Each piece is 1 minute long. Sorry for such a dumb script. Hope it is better to have dumb windows script and not have it at all. Maybe this helps someone. (Based on the "bat file for loop" from this site.)

 set var=0 @echo off :start set lz= if %var% EQU 50 goto end if %var% LEQ 9 set lz=0 echo part %lz%%var% ffmpeg -ss 00:%lz%%var%:00 -t 00:01:00 -i %1 -acodec copy -vcodec copy %2_%lz%%var%.mp4 set /a var+=1 goto start :end echo var has reached %var%. exit 
+2
May 08 '17 at 18:10
source share

Does the later approach support computation time and memory?

There is not much difference between the two examples that you provided. The first example cuts the video sequentially, in 2 stages, while the second example does this simultaneously (using streams). No particular acceleration will be noticeable. You can learn more about creating multiple exits using FFmpeg.

Alternatively, you can use (in recent FFmpeg) a stream stream multiplexer that can:

outputs streams to several separate files of almost fixed duration. The output of the file name template can be set in the same way as image2 .

+1
Aug 24 '13 at 9:51 on
source share

Here is a great way to split a video. I have done this before and it works well for me.

ffmpeg -i C:\xampp\htdocs\videoCutting\movie.mp4 -ss 00:00:00 -t 00:00:05 -async 1 C:\xampp\htdocs\videoCutting\SampleVideoNew.mp4 (for CMD). shell_exec('ffmpeg -i C:\xampp\htdocs\videoCutting\movie.mp4 -ss 00:00:00 -t 00:00:05 -async 1 C:\xampp\htdocs\videoCutting\SampleVideoNew.mp4') ( for php).

Please follow this and I am sure it will work perfectly.

+1
Jul 17 '18 at 12:36
source share

Not tested ist, but this looks promising:

Main stream segment

This, obviously, splitting AVI into segments of the same size, which means that these pieces do not lose quality or increase memory or should be recounted.

It also uses a copy of the codec - does this mean that it can handle very large streams? Since this is my problem, I want to break my avi, so I can use a filter to get rid of the distortion. But the whole avi works for several hours.

0
Sep 10 '13 at 12:22
source share

one simple way is to use the cropping option using url based api .

once you upload your video, just set the start offset and end offset to url (so_2, eo_2) as follows:

  https://media.publit.io/file/so_2,eo_2/tummy.mp4 

this will create instantly new videos starting from the second second and 2 seconds in length. You can share the video as you like.

0
May 15 '18 at 14:33
source share

It turns out that the size of the file (s) in a later case will be proportional to the equivalent of the temporary fragment.

-6
Sep 05 '11 at 5:22
source share



All Articles