LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 04-02-2007, 06:30 AM   #1
milkjerry3
LQ Newbie
 
Registered: Apr 2007
Posts: 7

Rep: Reputation: 0
Exclamation How do you split mpg files using a ffmpeg command?


thanks to anyone that can help me 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
 
Old 04-02-2007, 07:07 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949
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.
 
Old 04-03-2007, 05:31 AM   #3
milkjerry3
LQ Newbie
 
Registered: Apr 2007
Posts: 7

Original Poster
Rep: Reputation: 0
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?
 
Old 04-03-2007, 07:03 AM   #4
Emmanuel_uk
Senior Member
 
Registered: Nov 2004
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,604

Rep: Reputation: 47
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 :-)
 
Old 04-03-2007, 08:25 AM   #5
milkjerry3
LQ Newbie
 
Registered: Apr 2007
Posts: 7

Original Poster
Rep: Reputation: 0
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 ill make that a mental note, but how do you know if i looked it up or not? your magic
 
Old 04-03-2007, 01:12 PM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949
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.
 
Old 04-04-2007, 12:19 AM   #7
milkjerry3
LQ Newbie
 
Registered: Apr 2007
Posts: 7

Original Poster
Rep: Reputation: 0
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
 
Old 12-04-2008, 01:54 PM   #8
space_age
LQ Newbie
 
Registered: Dec 2008
Posts: 3

Rep: Reputation: 0
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.
 
Old 10-10-2009, 06:21 PM   #9
greengrocer
Member
 
Registered: Aug 2005
Distribution: Ubuntu Intrepid and Meerkat, formerly used Debian 3.1 (Sarge) with Gnome Desktop
Posts: 353

Rep: Reputation: 37
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.
 
Old 10-11-2009, 04:39 AM   #10
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
If we're talking about a regular mpeg2 file, then you can just use split or dd to split it.
 
Old 01-08-2010, 02:36 PM   #11
FlashM
LQ Newbie
 
Registered: Jan 2010
Posts: 1

Rep: Reputation: 0
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?
 
Old 08-29-2010, 07:58 AM   #12
KMCheese
LQ Newbie
 
Registered: Aug 2010
Posts: 1

Rep: Reputation: 0
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.
 
Old 09-05-2010, 08:04 AM   #13
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
'-sameq' is used when re-encoding a video, so I would also recommend using '-vcodec copy' instead.
 
Old 09-25-2010, 11:00 PM   #14
WSC
LQ Newbie
 
Registered: Sep 2010
Posts: 1

Rep: Reputation: 0
Quote:
Originally Posted by KMCheese View Post
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.
 
Old 03-06-2011, 02:52 PM   #15
matt99
LQ Newbie
 
Registered: Aug 2003
Posts: 2

Rep: Reputation: 0
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
 
  


Reply

Tags
file, how, mpg, split


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
where is the ffmpeg command line tool? leodemario Linux - Desktop 5 02-25-2007 03:11 PM
Need help with a short Linux command line script - working with split files bpmee Linux - Newbie 3 10-04-2006 02:08 AM
how does one use DD to recombine files from using pipe to split files originally? nerdful1 Linux - General 3 03-28-2006 07:46 AM
ffmpeg on slack 10.2 wmv to mpg Pier Slackware 2 01-05-2006 04:39 PM
mpg files MC62189 Linux - Newbie 3 01-14-2003 09:56 PM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration