Splitting a video into multiple parts

613

Solution 1

Here is a solution that worked for me.

For example:

avconv -ss 0 -i x.mp4 -t 180  -vcodec copy -acodec copy -metadata track="1" "Part I.mp4"              
avconv -ss 180 -i x.mp4 -t 164  -vcodec copy -acodec copy -metadata track="2" "Part II.mp4"              
avconv -ss 344 -i x.mp4 -t 185  -vcodec copy -acodec copy -metadata track="3" "Part III.mp4"   

I had 50 entries and I put them in a script together. I first put skeletons like

avconv -ss  -i x.mp4 -t   -vcodec copy -acodec copy -metadata track="  " ".mp4"  

Then I filled out the -ss and put the titles. After that, I used libreoffice Calc with space as a delimiter. I got the values for -t and track with a formula and dragging.

Solution 2

If you do this often you can try to create a bash script. Start with something like this:

#!/bin/bash

SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

FILES=$(ls *.mp4|sort)

let START=0

for FILE in $FILES
do
    echo Processing $FILE
    mkdir "${FILE}-chop"
    for COUNT in {1..59}
    do
        exec avconv -i "${FILE}" -ss $START -t 60 -c:v copy -c:a copy "./${FILE}-chop/${COUNT} - ${FILE}"
        let START=$START+60
    done
done

IFS=$SAVEIFS

Keep in mind that it's a very ugly code, and it will probably produce many errors and empty files, and won't work properly if the input file is more than an hour long, but it'll get you started.

Share:
613

Related videos on Youtube

Péter Kertész
Author by

Péter Kertész

Updated on September 18, 2022

Comments

  • Péter Kertész
    Péter Kertész almost 2 years

    I try to install a software for a thermal camera, but it gives the error message:

        pi@raspberrypi:~ $ sudo dpkg -i /media/pi/PETI/libirimager-1.1.7-i386.deb
    Selecting previously unselected package libirimager.
    (Reading database ... 112361 files and directories currently installed.)
    Preparing to unpack .../libirimager-1.1.7-i386.deb ...
    Unpacking libirimager (1.1.7) ...
    dpkg: dependency problems prevent configuration of libirimager:
     libirimager depends on libudev-dev (>= 1.0).
     libirimager depends on gcc (>= 4.6).
     libirimager depends on build-essential (>= 1.14.18).
     libirimager depends on cmake (>= 2.6).
    
    dpkg: error processing package libirimager (--install):
     dependency problems - leaving unconfigured
    Errors were encountered while processing:
     libirimager
    

    I tried the dpkg --configure -a , but did not solve the problem. The linux is totaly new for me, so I am unfamiliar with these orders. (Raspbian Jessie, i386)

    • Tasos
      Tasos about 10 years
      You can use command line --- ffmpeg -i input.mpg -ss 00:00:10 -t 00:00:30 out1.mpg -ss is the start point in hh:mm:ss from the beginning of your video file --- superuser.com/questions/31135/…
    • Tasos
      Tasos about 10 years
      If you want to just split the video without re-ecoding it, use the copy codec for audio and video. Try this: ----- ffmpeg -ss 00:00:00 -t 00:50:00 -i largefile.mp4 -acodec copy \ -vcodec copy smallfile.mp4
    • Tasos
      Tasos about 10 years
      can you check this solution, if you are familiar with scripts there is a nice script down the bottom yo can try --- stackoverflow.com/questions/5651654/…
    • romanbird
      romanbird about 10 years
      Yes, I know about it. I need to split a video of an opera into scenes/acts, etc.
    • Tasos
      Tasos about 10 years
      well you can try this --- ffmpeg -i in.mp4 -ss [start] -t [duration] -c:v copy -c:a copy out.mp4 --- source superuser.com/questions/377343/…
    • romanbird
      romanbird about 10 years
      This is better. Thanks. When I chain two outputs together the second one is frozen for the first few seconds.
    • Tasos
      Tasos about 10 years
      i believe i read somewhere but im not sure were, that you could also do multiple cuts in one command rather than doing it once every time. Cant remember though
    • romanbird
      romanbird about 10 years
      ya, thats what I did but the second one freezes for a few seconds: ffmpeg -i x.mp4 -ss 00:00:00 -t 00:00:50 -c:v copy -c:a copy out.mp4 -ss 00:00:49 -t 00:02:00 -c:v copy -c:a copy out1.mp4
    • Barafu Albino
      Barafu Albino about 10 years
      I believe that using copy codec one can only split videos on i-frames, which can be as rare as once per scene.
    • romanbird
      romanbird about 10 years
      what should I use then?
  • Péter Kertész
    Péter Kertész about 7 years
    Thank you for the fast answer. Now it is better, but I have still a message: 'This package is uninstallable' 'Dependency is not satisfiable: libudev-dev (>= 1.0)
  • Péter Kertész
    Péter Kertész about 7 years
    How can I install all dependencies? Are they independent files? I'm sorry for the silly questions...
  • tso
    tso about 7 years
    apt install libudev-dev gcc build-essential cmake
  • Knud Larsen
    Knud Larsen about 7 years
    Please edit your question to include OS name, version, architecture. This command will reply with i686 or x86_64 : uname -m
  • Toby Speight
    Toby Speight about 7 years
    The question is not on-topic for Stack Overflow as defined in the help center. Please don't answer such questions; instead, you should flag them for attention and they will be closed or migrated appropriately.
  • Knud Larsen
    Knud Larsen about 7 years
    libudev-dev, Jessie : libudev-dev_215-17 ... seems to be "later than 1.0". packages.debian.org/jessie/libudev-dev >>> arm64 packages.debian.org/jessie/arm64/libudev-dev/download