Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

Cut MP4 file

ulisses87
Beginner
761 Views

Hi,

I have an MP4 source video file. I also have numbers of start and end frames of commercials, which I want to cut out from original file, to produce clean output file with the same encoding parameters as source file.

My question: what is the fastest way to cut off these blocks of video? Each commercials begins with I-frame. I wouldn't to process again the whole file.

I have basic knwoledge how I can decode the video.

BTW:Could you tell me how I can disbale saving source video file as output YUV file (fwRender class object)?


Thanks.

0 Kudos
19 Replies
ulisses87
Beginner
761 Views

Really, nobody can help me?

I don't expect ready to use code - only small tip, how I can solve my problem...

0 Kudos
Tamer_Assad
Innovator
761 Views
Hi ulisses,


Please check the following thread:

http://software.intel.com/en-us/forums/showthread.php?t=78559

Regards,
Tamer Assad

0 Kudos
ulisses87
Beginner
761 Views

Hi,

Thank you for yor reply. I have studied your thread carefully, but unfortunately I think it isn't what I'm looking for. In this way I can extract and save commercials from source video file, but I want to do something inversely - I need to extract movie from video file.

For example I have video mp4 file like this: movie1|commercial1|movie2|commercial2|movie3 .

I want to get file like this: movie1|movie2|movie3 .

I'm looking for the fastest way to do this. I thought about something like editing existing file without re-encoding instead of rewriting movies part. In this way I would merge movie parts of video file and throw away commercials blocks.

Is it possible with IPP? Or maybe my idea is unreasonable and I must render and rewerite expected movie blocks?

Regards

0 Kudos
Tamer_Assad
Innovator
761 Views

Hi ulisses,

What if you think about your movie as an ARRAY on which you can perform a SORT operation?

Using the technique in the referenced thread will help you identify the movie parts and deal with them as array elements, so then you can sort them the way you want.

For example:

Array1 [movie1|commercial1|movie2|commercial2|movie3]

Sorted it To

_Array1 [movie1| movie2| movie3| commercial1|commercial2]

Or maybe better for your requirement to sort to a new array (different file) directly

_Array2 [movie1 |movie2| movie3]

You still must identify the starting point of each portion and mark it visually.

Regards,

Tamer Assad
0 Kudos
ulisses87
Beginner
761 Views
I understand your point of view, but in your proposition I need to read and re-encode all movie frames from source file, meanwhile I need to do cut off parts from my file without trancoding or preprocessing (something like MP4Box or AviDemux tools).
0 Kudos
Tamer_Assad
Innovator
761 Views

Hi ulisses,

This operation does't require any decoding/encoding efforts.
It can simply be achieved as follows:

Splitter.GetNextData(&in,videoTrack);
Muxer.PutVideoData(&in);

// then process audio track


The point is, the splitter get/identify frames from the input stream.
Muxer is required then to place frames correctly in the output stream.

You may do this by over-writting, but the file header might need to get rebuilt, also, the tail must be trimmed.
Writting to a temp file(memory file), then replace the original file when done, can do better.

Regards,

Tamer Assad
0 Kudos
ulisses87
Beginner
761 Views

Now I understand. Thanks for your effort. It's working.

But now I have a big problem.Sergey Osipov (http://software.intel.com/en-us/forums/showthread.php?t=79395&o=a&s=lr) reccomends me to use SampleBufferClass instead of fwRender to avoid wiriting to *.yuv output file during file analysis. Unfortunately I can't use SampleBuffer.

Could you help me? It's very importnat for me, because it's part of my Bsc Thesis final project and I have a deadline for a few days.

0 Kudos
Tamer_Assad
Innovator
761 Views

Hi ulisses,

Thank you for sharing the result.

Concerning your problem with fwRender and SampleBuffer, it would be helpful if you can provide an additional description of what you want to do.

If got that right and what you need now is to write your output data to a file, the UMC::FileWriter object associated with your muxer object is what you are looking for, it will write out the muxed data appropriately.

Please do send your feedback.

Regards,

Tamer Assad
0 Kudos
ulisses87
Beginner
761 Views

Hello,

Thanks for your quick reply.

Firstly - what I need to do. I don't want to save any data to the output file. I only want to process video in memory.

Secondly - why?

My algorith has two passes:

1.) Analyzing each frame of video data for commercials existing - in this pass I don't want to save any data on hard drive yet.

2.) Cutting source video at calculated positions and splitting file to one smaller file without tv commercials (this is what you help me to do).

Summary: I need processing video frame by frame and I don't want to create any output file on my hard drive. How I can do it in details?

0 Kudos
Tamer_Assad
Innovator
761 Views

Hi ulisses,

Following the previous example, do you mean to have /* Muxer.PutVideoData(&in); */ to write to a memory buffer rather than an associated file?

Regards,

Tamer Assad

0 Kudos
ulisses87
Beginner
761 Views

Yes, but not really. You are right, that I don't want any associated file. I want to keep in memory only ONE currently processed frame. Previously processed frames aren't interesting for me. Current frame doesn't need an extra space, because it would overwrites previously processed data. Please look at this pseudo-code (in big simplification):

[cpp]do{
    buffer = GetAndDeocdeOneFrame();
    //do something with one image of frame
}

Is it possible to do in IPP?



[/cpp]

0 Kudos
Tamer_Assad
Innovator
761 Views

Hi ulisses,

This is alright, you just need implement the UMC::DataWriter abstract class.
UMC::DataWriter is the base class of the UMC::FileWriter.

Follow the UMC::FileWriter implementation and create your own "BufferWriter" class, associate a "BufferWriter" object with the muxer object directly.

Regards,

Tamer Assad

0 Kudos
ulisses87
Beginner
761 Views

Hi,

This is different way than this recommended in posthttp://software.intel.com/en-us/forums/showthread.php?t=79395&o=a&s=lr . Please take a look to attached part of code in my post. In the first pass of my algorithm I don't use any muxer object. I only use splitter and decoder as it was explained on Intel webiste: http://software.intel.com/en-us/articles/getting-started-with-intel-ipp-unified-media-classes-sample/ in chapter "Using a splitter". I want to get something like this part of code but the data shouldn't be saved in YUV or in any other file:http://software.intel.com/file/23815 .

I know that fwRender is responsible for sending rendered data to output file, so I think that I need to replace this object with another. What do you think?

0 Kudos
Tamer_Assad
Innovator
761 Views

Hi ulisses,

If Im following correctly, what you want is to get decoded YUV frames to your buffer, not muxed frames, right?

If this is the case, you do not need any rendering process, all you need is to decode your frames and use your existing calls to out.GetPlanePointer or call out.GetBufferPointer() once per frame;

The decoder outputs YUV frames already!

Renders basically forwards frames to rendering surface at the GPU memory, fwRender just simulates this process and writes frames to a file, you don't need to use it, so don't :)

Regards,

Tamer Assad

0 Kudos
ulisses87
Beginner
761 Views

Yes. I think that you understand correctly what I want to do.

So, it was my first this - simply remove line fwRender.RenderFrame(), but it doesn't work. Next frame aren't processed... and whole loop is infinite.

0 Kudos
ulisses87
Beginner
761 Views
It doesn't have any sense. I have tried to put away fwRender.RenderFrame() for few hours with many ways, but then I always can to process only the first frame and next frames are locked... :(
0 Kudos
Tamer_Assad
Innovator
761 Views

Hi ulisses,

I meant that you remove/comment ALL fwRender calls, not just RenderFrame()

I suggest you create smaller test programs, in order to break down problems and get them solved, one at a time.

Create a new small program that just split and decode without rendering AT ALL, place break points and check the variables memory at the debug time. Refer to Chaos sample splitter and Example 5-61 MP4Splitter Usage Example at the UMC manual.

Make it as simple as possible!

Regards,

Tamer Assad

0 Kudos
Tamer_Assad
Innovator
761 Views

Hi ulisses,

I have posted a modified version ofChaos simplesplitter.cpp to a new thread with a more relevant title, as this issue is beyond the scope of this thread, so you can get best possible support, and other members can share information.

The question of this thread regarding the iteration of an mp4 stream was answered already in

post #6

Splitter.GetNextData(&in,videoTrack);
Muxer.PutVideoData(&in);

I hope you find the answer to your question about the splitter in the relevant thread, se attached code, file contains a working code that I modified.

http://software.intel.com/en-us/forums/showthread.php?t=79801&o=a&s=lr

Regards,

Tamer Assad

0 Kudos
ulisses87
Beginner
761 Views

Hi,

Many thanks for your effort. I see that you merged and modified two code examples (decoder and splitter from Chao). I'll test your solution in details tommorow, but I have only one doubt now after reading this.

I see you use cYUVData buffer for storing all the decoded frames and size of this buffer is limited by MAXYUVSIZE parameter. What's more number of iteration is controlled by MAXFRAMESIZE parameter, so if size of my video file would be bigger than this limit it will be cut.

Is it possible to create similar buffer only for one frame per iteration? Potential problem is that the SetBufferPointer expects two parameters: pointer to buffer and frame size.

Anyway again thanks for the new point of view.

Regards,

Ulisses87

0 Kudos
Reply