LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How do you split mpg files using a ffmpeg command? (http://www.linuxquestions.org/questions/linux-newbie-8/how-do-you-split-mpg-files-using-a-ffmpeg-command-542607/)

milkjerry3 04-02-2007 06:30 AM

How do you split mpg files using a ffmpeg command?
 
thanks to anyone that can help me :D i want to split a mpg file so that i can burn it onto a cd because the one i have now is too big to fit on a cd... i want to be able to use a ffmpeg command because its easier for me, but if there is another easy way i would like to know :) iv'e been searching google for ages but i havent found anything.. so i thought i could find out how to here :) soooooooooooooooooooo... if anyone could help me i will be very happy :D

David the H. 04-02-2007 07:07 AM

Did you try the man page? ffmpeg has two options, '-ss' (seek to position), and '-t' (recording duration). Basically, you set up a stream copy, use -ss to go to the point where you want to start the segment, then use -t to set the length of the recording from that position. You'll have to do it once for each segment you want to create.

An easier way would be to get mpgtx, which includes a variety of mpg tools including a splitter, and can do splits in a variety of ways.

milkjerry3 04-03-2007 05:31 AM

Quote:

Originally Posted by David the H.
Did you try the man page? ffmpeg has two options, '-ss' (seek to position), and '-t' (recording duration). Basically, you set up a stream copy, use -ss to go to the point where you want to start the segment, then use -t to set the length of the recording from that position. You'll have to do it once for each segment you want to create.

An easier way would be to get mpgtx, which includes a variety of mpg tools including a splitter, and can do splits in a variety of ways.

how do you use mpgtx though?

Emmanuel_uk 04-03-2007 07:03 AM

you go there and read
http://mpgtx.sourceforge.net/#Usage

It is a usage to make your own homework before asking question, or lets put it that way, you are expected to do some homework/reading first

Welcome to LQ anyway, not everybody will be as stern as me :-)

milkjerry3 04-03-2007 08:25 AM

Quote:

Originally Posted by Emmanuel_uk
you go there and read
http://mpgtx.sourceforge.net/#Usage

It is a usage to make your own homework before asking question, or lets put it that way, you are expected to do some homework/reading first

Welcome to LQ anyway, not everybody will be as stern as me :-)

thanks :D ill make that a mental note, but how do you know if i looked it up or not? :eek: your magic :D

David the H. 04-03-2007 01:12 PM

You'll find that the *nix community is very big on encouraging people to 'RTFM' before they ask for help. :)

And people who have made the attempt usually indicate it in some way. Something like "I read the instructions, but I still don't understand what to do", followed by some detailed questions on use, would tell us that you at least gave it the effort first.

FYI, your first stop should always be the man page. In a terminal/console, simply type "man <command>" and you'll (usually) get a general how-to-use manual page for it. The mpgtx man page, in this case, is fairly detailed and should give you enough info on how to use it. If it's still unclear to you, then you can come back and ask about it. Be sure to make it clear what you do understand, as well as what you don't.

milkjerry3 04-04-2007 12:19 AM

Quote:

Originally Posted by David the H.
You'll find that the *nix community is very big on encouraging people to 'RTFM' before they ask for help. :)

And people who have made the attempt usually indicate it in some way. Something like "I read the instructions, but I still don't understand what to do", followed by some detailed questions on use, would tell us that you at least gave it the effort first.

FYI, your first stop should always be the man page. In a terminal/console, simply type "man <command>" and you'll (usually) get a general how-to-use manual page for it. The mpgtx man page, in this case, is fairly detailed and should give you enough info on how to use it. If it's still unclear to you, then you can come back and ask about it. Be sure to make it clear what you do understand, as well as what you don't.


ok thanks :D

space_age 12-04-2008 01:54 PM

Try the:
-vcodec copy
option to copy as well as the -ss and -t options mentioned above.

Example: ffmpeg -vcodec copy -ss 00:01:00 -t 00:03:00 -i infile.mpg outfile.mpg

the -vcodec option chooses the video codec to use, more options are:
-vcodec <string> : Force video codec.
copy : Copy raw codec data as is.
dvvideo : DV Video (for video editing, I've heard)
ffv1 : FFV1 lossless video codec
h264 : H.264 (best mpeg-4 codec, I've heard)
mpeg2video : MPEG-2 Video
rawvideo : RAW Video
xvid : XviD ( MPEG-4 Part 2 )

(-vcodec options from http forum dot videohelp dot com slash topic338564 dot html ) I can not post proper url's yet.

greengrocer 10-10-2009 06:21 PM

I know this is an old thread, however for the benefit of those who stumble upon this thread from googling...

This is also useful use of ffmpeg.

ffmpeg -i inputfilename.mpg -sameq -ss 00:01:00 -t 00:03:00 outfile.mpg

The above will extract 3 minutes of mpg file from the 1 minute mark using same quality as the source file. This is useful for Variable Bit Rate (VBR) encoded files.

The -sameq parameter tells ffmpeg to use same quality as input file.

H_TeXMeX_H 10-11-2009 04:39 AM

If we're talking about a regular mpeg2 file, then you can just use split or dd to split it.

FlashM 01-08-2010 02:36 PM

Hi!


I'm trying to split my 50 minutes video file into 30 seconds long chunks. How could I achieve this with FFMPEG? I wrote a simple C# application that would start a process in a loop but it seems it's taking ages to split my file.

My code looks something like this:

Code:

class Program
    {
        private static TimeSpan ts = new TimeSpan(0, 0, 0, 00);
        private static TimeSpan tsAdd = new TimeSpan(0, 0, 0, 30);

        private static string timeSpan = "00:00:30";

        static void Main(string[] args)
        {
            for (int i = 0; i <= 108; i++)
            {
                string fileName = string.Format("{0:00}{1:00}{2:00}.flv", ts.Hours, ts.Minutes, ts.Seconds);
                string startTime = string.Format("{0:00}:{1:00}:{2:00}", ts.Hours, ts.Minutes, ts.Seconds);

                ProcessStartInfo info = new ProcessStartInfo();
                info.FileName = @"C:\ffmpeg";
                info.Arguments = string.Format("-i C:\\Movie.flv -sameq -ss " + startTime + " -t " + timeSpan + " C:\\OutputFolder\\" + fileName);
                info.CreateNoWindow = true;
                info.UseShellExecute = false;

                Process process = Process.Start(info);
                process.WaitForExit();

                if (process.ExitCode != 0)
                {
                                        //Whatever goes here
                }

                process.Close();
                process.Dispose();

                ts = ts.Add(tsAdd);
            }
        }
    }

Does anyone have any better idea?

KMCheese 08-29-2010 07:58 AM

Effect of "-sameq"
 
Hi! I am new to ffmpeg. Actually, I am using it on a Mac but this thread has been useful to me so I thought I would add what I have learned by testing ffmpeg to split mpg files.

I tried greengrocer's suggestion and used "-sameq" as recommended to split part of an mpeg2video file. The video quality was, indeed, unchanged as far as I could see but when I checked it by typing in

ffmpeg -i resulting_file.mpg

and hitting return I saw that it had been changed from a mpeg2video to a mpeg1video. When I used space_age's command, that is

ffmpeg -vcodec copy -ss 00:01:00 -t 00:03:00 -i infile.mpg outfile.mpg

I found that the resulting file remained mpeg2video. Moreover, it was considerably smaller. I also used the -vcodec copy command to copy the entire file and found that it was just slightly smaller than the original. I'm not sure what was lost but after experimenting with the two I would say that "-vcodec copy" is what fits my needs.

I apologize for posting this so long after discussion has died down. However, as I found this discussion through a search engine, I thought I would post my experience for those who might also be Googling for this kind of information.

H_TeXMeX_H 09-05-2010 08:04 AM

'-sameq' is used when re-encoding a video, so I would also recommend using '-vcodec copy' instead.

WSC 09-25-2010 11:00 PM

Quote:

Originally Posted by KMCheese (Post 4081377)
I apologize for posting this so long after discussion has died down. However, as I found this discussion through a search engine, I thought I would post my experience for those who might also be Googling for this kind of information.

No need to apologize! Even though this thread started early 2007, I too found all this info invaluable.

After searching for days and downloading various video converting programs, wasting lots of time in trying them out, none could directly stream copy or split videos. I was just about to give up, but stumbled upon this thread. After downloading FFMPEG and trying out the options listed here, it finally worked for me. I am very, very pleased with this "powerful" program.

At first, I also had problems with the -sameq option. I can't remember exactly. When running it, errors came up at the command prompt. I think it also changed the video format.

BTW, no one mentions stream coping and splitting the audio part with the option -acodec copy. Here are the options that worked for me with both video and audio:

ffmpeg -i some_video.flv -vcodec copy -acodec copy -ss 00:00:00 -t 00:02:24 cut_video.flv

The cut_video.flv was a carbon copy of the original except shorter; same resolution, codecs, aspect ratio and bit rates.

Hope this thread helps others like it did me.

matt99 03-06-2011 02:52 PM

I'll second the last post. I've wasted time trying to do the seemingly simple operation of cutting a big mpeg file in two, getting nowhere, and just finding a hoard of windows shareware programs.

Thanks to this thread my problem is solved, with a similar ffmpeg invocation to that in the previous post :)


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