LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Breaking avi file into 3 via the commandline? (http://www.linuxquestions.org/questions/linux-newbie-8/breaking-avi-file-into-3-via-the-commandline-597321/)

Maverick1182 11-05-2007 02:29 PM

Breaking avi file into 3 via the commandline?
 
Hi there,

I am currently trying to break a large .avi file into three equal chunks. I want it to be done slick in commandline as I dont want to go through the bother of a GUI to select points I want etc. Recommendations have pointed me to the avidemux command line interface. Unfortunately, it seems to miss frames when it breaks the file into fixed sizes... this means that when I try to patch them together there is a noticable skip where the cut has occurred. I was wondering if there are any other simple commandline utilities I could try to simple break one large avi file into 3 files of identical size without loss of frames?

druuna 11-05-2007 04:17 PM

Hi,

You could have a look at the split command. And use cat to put them back together again (cat a b c d > abcd).

Hope this helps.

Maverick1182 11-05-2007 05:08 PM

can this be done to an avi? I dont know how its encoded but I will see if this can be done...

matthewg42 11-05-2007 05:11 PM

I don't think split is appropriate as it has no idea where to break the file - it uses criteria like number of bytes, lines and so on. I assume that splitting an avi file would require the addition of some sort of headers to each file, and probably choosing a split point at a key frame, or adding a new one at the start of the second and third chunk.

Maverick, what is the format of the video? As I understand it, AVI is just a container, and may contain one of a large number of codecs. Many codecs are supported by Linux programs, but a few are less commonly or less well supported.

Assuming the codec in one which can be handled, you could use one of the various transcoding tools to extract and re-encode a segment of the original file. This is not ideal because you would lose quality and it will take a lot of CPU power.

What would be ideal would be a way to do the edits without having to re-encode everything. I don't know how to do this with video, sorry. With audio (ogg or mp3) you can use mp3splt. I'm guessing you want that sort of thing but for video.

Maverick1182 11-06-2007 03:44 AM

The video I need to split is coded in DivX. Any ideas/experiences on a program which could do this? I need to spilt it using the commandline so which ever program it is , there needs to be a commandline interface. Hoping someone can help...

matthewg42 11-06-2007 04:15 AM

I just found that there is a program called avisplit on my system which seems to work on DivX files. This program is part of the transcode package (at least it is on Ubuntu).

You can specify to split by maximum size of output file, or by time.

e.g.
Code:

avisplit -s 20 -i big_file.divx -o splitted
This will split big_file.divx into 20 Mb chunks.

jschiwal 11-06-2007 04:38 AM

Do you want to split the avi file to produce 3 separate playable avi files, or do you want to split the file just due to the size; Such as posting on usenet or sending slices via email, or not exceeding the filesize limit? If it is the latter, then you can use the split command to split the file up into slices. I've done this to store a backup of my home directory before an upgrade. The external drive I had handy used the FAT32 filesystem.
I think that avisplit will break up a video into shorter videos.

Maverick1182 11-06-2007 07:33 AM

I will have a try with avisplit. I actually need the 3 smaller files to be seperate playable files so, as you say, I think avisplit is probably best. matthewg42, when you split the files and play them sequencially (say in vlc playlist), is there a noticable jump when it changes from one file to the other? This is what I have experienced in avidemux. I dont know if it is intelligent enough (or what it does) when you ask it for files a certain size, whether it creates one file of say 20MB and then starts at exactly the next frame to generate the next file etc...

Any input/information would be helpful but in the meanwhile I will try out avisplit when I get home and post back. Thanks for the help so far.

matthewg42 11-06-2007 07:48 AM

I just tried it, and I see what you mean - looks like there are jumps and overlaps. I have no idea how to remedy that.

Maverick1182 11-06-2007 08:02 AM

Bummer, (thanks for testing it Matthew) would anyone know of software which cuts the file according to the frame number? At least then I can have control over how the three smaller files are created and avoid this clipping problem?

druuna 11-06-2007 05:14 PM

Hi,

You could take a look at mencoder. This does means that you to need to add headers to the individual parts.

Very roughly you can do something like this:

mencoder INFILE -ss 00:00:00 -endpos 00:00:00 -ovc lavc -oac copy -forceidx -o OUTFILE.avi

Although it's wise to take a look at the other options used (are divx options needed??) and to check the manpage (man mplayer), the options that concern your question are:

-ss 00:00:00 (Seek to given time position).
and
-endpos (Stop at given time or byte position).

-ss 00:01:30 -endpos 00:00:30 will start playing one minute and thirty seconds into the movie and will play for 30 seconds. The actual start and stop point are chosen by mencoder, there's no hard cut-off. I never tried using the byte position (-endpos 100mb), and don't know if this is or is not a hard cut-off.

Anyways, Hope I gave a better answer then the previous one ;)

jschiwal 11-07-2007 03:36 AM

If you simply split the file, you could play it with "mplayer <(cat /path/to/file/name.avi.*)"

Maverick1182 11-09-2007 03:27 AM

Okay, I've tried all the solutions and played the broken files back... The best at breaking the file into 3 without loss of frames seems to be mencoder using precise time stamps rather than file size. It's a little slower but seems to get the job done. I hope this helps anyone else who wants to do what I wanted to do....

Thanks everyone for posting suggestions (please do , if anyone has a better/faster option)

mencoder INFILE -ss 00:00:00 -endpos 00:00:00 -ovc lavc -oac copy -forceidx -o OUTFILE.avi


All times are GMT -5. The time now is 04:05 AM.