How do you split mpg files using a ffmpeg command?
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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.
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.
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.
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.
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.
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);
}
}
}
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
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.
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:
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.