LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How do you split mpg files using a ffmpeg command? (https://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.

anon254 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 :)

rport 04-03-2011 04:54 PM

No problem to split with MP4Box
 
MP4Box seems to be another great tool to do things like this.

To split an .mp4 file into files of a maximum desired file size, e.g. 4000 kb, enter:

MP4Box -splits 4000 original_file.mp4

This will generate files original_file_001.mp4 , original_file_002.mp4 and so on.

There are also options for maximum duration in seconds, or for start and end time in seconds.

MP4Box comes with the gpac package (in my case version 0.4.5-1.pm.3.1 under SuSE 11.3)
and worked for me on first attempt.

Have fun!

sarbojit 05-11-2011 06:24 AM

how to do this?
 
I have found this mail thread is quite help full for my current requirement. I tried some variation with given commands but did not get success.
Actually I wanted to convert a .VOB file into mp4 format but I wanted to convert it into small chunks.
Here as per the given example I can split a video file into same format like mpeg to mpeg but I want to split + convert at the same time. Please let me know if it is possible.

Commands that I have tried are below.
ffmpeg -i S.vob -vcodec copy -ss 00:01:00 -t 00:02:00 y.avi

Also when I am converting .VOB file into .AVI using below command, video quality is getting worst.
ffmpeg -i s.vob -f avi -vcodec mpeg4 -b 800k -g 300 -bf 2 -acodec libmp3lame -ab 128k z.avi

H_TeXMeX_H 05-11-2011 07:57 AM

Use '-qscale' and 2 pass encoding to get better quality, see:
http://htexmexh.byethost13.com/linux/encoding.html

I would split it before encoding, it's just easier. That way you can run a for loop, and encode them all.

sarbojit 05-12-2011 04:31 AM

Thanks H_TeXMeX_H,
It helped, now I am getting same quality but facing a new problem now. Even though I am mentioning video and audio encoding formats as "-vcodec mpeg4" and "-acodec libmp3lame" but not able to play on IPAD. AFAIK, ipad supports mp4 then why it is not getting played? Do I need to set any other flag to make it IPAD compatible? The command that I am using is,
"ffmpeg -i S.vob -vcodec mpeg4 -vtag xvid -qscale 5 -s 640x272 -aspect 40:17 -r 23.976 -g 240 -bf 2 -acodec libmp3lame -ab 160k -ar 48000 -async 48000 -ac 2 test.avi "

Note: If I change the file name from test.avi to test.mp4 then it is giving error message. "[mp4 @ 01f8d010] Tag xvid/0x64697678 incompatible with output codec id '13'".

I actually need to convert vob files into a format which can be run on IPAD.

H_TeXMeX_H 05-12-2011 08:09 AM

.mp4 is a format, so is .avi, so if it only plays .mp4, encode it to .mp4, not .avi.

Quote:

Video formats supported: H.264 video up to 720p, 30 frames per second, Main Profile level 3.1 with AAC-LC audio up to 160 Kbps, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats; MPEG-4 video, up to 2.5 Mbps, 640 by 480 pixels, 30 frames per second, Simple Profile with AAC-LC audio up to 160 Kbps per channel, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats; Motion JPEG (M-JPEG) up to 35 Mbps, 1280 by 720 pixels, 30 frames per second, audio in ulaw, PCM stereo audio in .avi file format
http://www.apple.com/ipad/specs/

It looks like .avi is supported, but only with mjpeg video and PCM audio, so do encode to .mp4.

I don't see why you don't use x264 instead tho, it's a better encoder and it is supported, and use AAC with it, and .mp4 format. See the same link I posted for x264 encoding. I hope it still works because ffmpeg syntax has changed recently, and I will have to update the guide.

Try:

Code:

ffmpeg -i input.vob -vcodec libx264 -vpre special -crf 15 -s 704x396 -aspect 16:9 -r 23.976 -threads 4 -acodec libfaac -ab 128k -ar 48000 -async 48000 -ac 2 -scodec copy output.mp4
You can use a different preset if you like, any will work, like 'hq'. Make sure to put the right resolution, aspect, FPS, etc.


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