0

I'm working on a Transcoding video project and I need to split a video file into multiple files.

Input file is in Y4M format.

Output files are also in Y4M format with 8 frames per video file.

How can I do it using ffmpeg?

Rotem
  • 30,366
  • 4
  • 32
  • 65
asendjasni
  • 963
  • 1
  • 16
  • 36
  • Use [ffmpeg](https://ffmpeg.org/) [http://stackoverflow.com/questions/14005110/how-to-split-a-video-using-ffmpeg-so-that-each-chunk-starts-with-a-key-frame](http://stackoverflow.com/questions/14005110/how-to-split-a-video-using-ffmpeg-so-that-each-chunk-starts-with-a-key-frame) – Rotem Feb 23 '17 at 15:46
  • thanks @Rotem I will try do so. – asendjasni Feb 24 '17 at 16:11
  • I'm back to you, What i didn't mention in the question, is that I'm working with rawvideo, the link you give it to me work only with other video container. Can you help me with this ?@Rotem – asendjasni Mar 15 '17 at 12:05
  • GOP is not well defined for raw video. [https://en.wikipedia.org/wiki/Group_of_pictures](https://en.wikipedia.org/wiki/Group_of_pictures). Please explain what do you mean by "split the video into GOPs". Do you mean group of raw video frames, or group of compressed video frames starting with I - Frame (key frame)? – Rotem Mar 15 '17 at 12:24
  • Well, what I want to do is encode a rawvideo(Y4m) with libx265 using Ffmpeg but in parallel mode, for that I need to split(segment) the input into several segment so that each node encode a segment. The segment is defined by a number of frames. – asendjasni Mar 15 '17 at 12:36
  • So all you need (for now) is splitting the large Y4m into multiple small Y4m files, with 8 frames per "small" file? – Rotem Mar 15 '17 at 12:39
  • Yes that exactly what I need. – asendjasni Mar 15 '17 at 12:41
  • 1
    I found a solution using `ffmpeg`. I edited your question to match your intent. – Rotem Mar 15 '17 at 14:40

1 Answers1

1

I found a solution (using ffmpeg).

The following example creates sample input file (for testing), and split it into parts.
In my example, the input file contains 8 frames per second, and the splitting process creates one output file for each second.
(I tried using option -segment_frames 8 instead of -segment_time 1, but it's not working).

Create input file (for testing):
Create AVI file and convert AVI file into y4m format file:

ffmpeg -f lavfi -i testsrc=duration=10:size=160x120:rate=8 -c:v rawvideo -pix_fmt bgr24 -y input.avi
ffmpeg -i input.avi -pix_fmt yuv444p input.y4m

Split file into segments of 8 frames (1 second per video file):

For Windows (use %%):

ffmpeg -i input.y4m -f segment -segment_time 1 -pix_fmt yuv444p output%%4d.y4m

For Linux (use %):

ffmpeg -i input.y4m -f segment -segment_time 1 -pix_fmt yuv444p output%4d.y4m
Rotem
  • 30,366
  • 4
  • 32
  • 65
  • So your solution is to change the frame rate of the video than split it, could that have an effect on the quality of the video ? – asendjasni Mar 15 '17 at 18:11
  • I tried the command for linux, it worked perfectly in the terminal, but when I use it on matlab `function [] = segmenting(dir)` `cd(dir);` `videoNameIn = 'galleon_422_cif';` `videoNameOut = 'segment';` `videoType = '.y4m';` `segmentTime = 1;` `pix_fmt = 'yuv422p';` `system(['ffmpeg -i ', videoNameIn, videoType, ' -f segment -segment_time ', num2str(segmentTime), ' -pix_fmt ', pix_fmt , videoNameOut,'%3d',videoType]);` `end` I got an error : `At least one output file must be specified` – asendjasni Mar 15 '17 at 19:37
  • You don't need to change the frame rate, you can use fractions of seconds. Example: `ffmpeg -i input.y4m -f segment -segment_time 0.5 -pix_fmt yuv444p output%4d.y4m`. Set `-segment_time` parameter to **8/framerate** – Rotem Mar 15 '17 at 21:14
  • 1
    About the error: You missed a `space` after `yuv422p`. It should be: `system(['ffmpeg -i ', videoNameIn, videoType, ' -f segment -segment_time ', num2str(segmentTime), ' -pix_fmt ', pix_fmt, ' ', videoNameOut,'%3d',videoType]);` – Rotem Mar 15 '17 at 21:21
  • You should learn how to debug your own code... without the space you are getting `yuv422psegment001.y4m` instead of `yuv422p segment001.y4m`... – Rotem Mar 15 '17 at 22:48
  • Thanks a lot I really appreciate it. – asendjasni Mar 15 '17 at 23:15