Decode H264 and save to yuv file

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Decode H264 and save to yuv file

edward20
Hello everyone,

I am new here and I am trying to decode video using ffmpeg c API and save as yuv file with YUV420P pixel format.

All examples that I have seen they converting extracted frames to RGB or PPM and then saving them to file.
But I want to save as YUV. I don't know do I have to convert frames after decoding them or maybe after decoding the frames are already YUV frames. Any help will be appreciated.

Thanks in advance

Edward.
Reply | Threaded
Open this post in threaded view
|

Re: Decode H264 and save to yuv file

Paul B Mahol
On 7/26/13, edward20 <[hidden email]> wrote:

> Hello everyone,
>
> I am new here and I am trying to decode video using ffmpeg c API and save
> as
> yuv file with YUV420P pixel format.
>
> All examples that I have seen they converting extracted frames to RGB or
> PPM
> and then saving them to file.
> But I want to save as YUV. I don't know do I have to convert frames after
> decoding them or maybe after decoding the frames are already YUV frames.
> Any
> help will be appreciated.

Usually videos are in yuv420 and decoder outputs it in yuv420 planar
format. So after decoding there is nothing left to do.

But perhaps you need packed yuv format?
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Decode H264 and save to yuv file

Spirian
In reply to this post by edward20
Normally, Decode means converting an codec format to .yuv or rgb24 format.
for ffmpeg : ffmepg -i x1.avi x2.yuv  x1=input x2=output  




------------------ Original ------------------
From:  "Paul B Mahol"<[hidden email]>;
Date:  Sat, Jul 27, 2013 04:00 AM
To:  "FFmpeg user questions"<[hidden email]>;

Subject:  Re: [FFmpeg-user] Decode H264 and save to yuv file



On 7/26/13, edward20 <[hidden email]> wrote:

> Hello everyone,
>
> I am new here and I am trying to decode video using ffmpeg c API and save
> as
> yuv file with YUV420P pixel format.
>
> All examples that I have seen they converting extracted frames to RGB or
> PPM
> and then saving them to file.
> But I want to save as YUV. I don't know do I have to convert frames after
> decoding them or maybe after decoding the frames are already YUV frames.
> Any
> help will be appreciated.

Usually videos are in yuv420 and decoder outputs it in yuv420 planar
format. So after decoding there is nothing left to do.

But perhaps you need packed yuv format?
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Decode H264 and save to yuv file

edward20
Spirian wrote
Normally, Decode means converting an codec format to .yuv or rgb24 format.
for ffmpeg : ffmepg -i x1.avi x2.yuv  x1=input x2=output  




------------------ Original ------------------
From:  "Paul B Mahol"<[hidden email]>;
Date:  Sat, Jul 27, 2013 04:00 AM
To:  "FFmpeg user questions"<[hidden email]>;

Subject:  Re: [FFmpeg-user] Decode H264 and save to yuv file



On 7/26/13, edward20 <[hidden email]> wrote:
> Hello everyone,
>
> I am new here and I am trying to decode video using ffmpeg c API and save
> as
> yuv file with YUV420P pixel format.
>
> All examples that I have seen they converting extracted frames to RGB or
> PPM
> and then saving them to file.
> But I want to save as YUV. I don't know do I have to convert frames after
> decoding them or maybe after decoding the frames are already YUV frames.
> Any
> help will be appreciated.

Usually videos are in yuv420 and decoder outputs it in yuv420 planar
format. So after decoding there is nothing left to do.

But perhaps you need packed yuv format?
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Thanks for your reply but actually I need an example of C code how to save frames in file after decoding video and extracting frames. Can you provide me an example?
Reply | Threaded
Open this post in threaded view
|

Re: Decode H264 and save to yuv file

edward20
Anyone? Please I just need part of C code which
explains how to write decoded YUV data to file.
Is there any example of it?

Here is what I have tried so far



void write_frame_to_file(AVFrame* frame, int width, int height, int iframe)
{
        FILE* outfile;
        char filename[32];
        int y;

        // Open file
        sprintf(filename, "frame%d.yuv", iframe);
        outfile = fopen(filename, "wb");
        if (outfile == NULL) {
                return;
        }

        // Write pixel data
        for (y = 0; y < height; ++y) {
                fwrite(frame->data[0]+y*frame->linesize[0], 1, width*3, outfile);
        }

        // Close file
        fclose(outfile);
        printf("file is closed\n");
}
Reply | Threaded
Open this post in threaded view
|

Re: Decode H264 and save to yuv file

Pavel Koshevoy
On 7/30/2013 2:25 AM, edward20 wrote:
> Anyone? Please I just need part of C code which
> explains how to write decoded YUV data to file.


You are asking API questions on the wrong mailing list.  API questions
are answered on https://lists.ffmpeg.org/mailman/listinfo/libav-user/


> Is there any example of it?

http://ffmpeg.org/doxygen/trunk/examples.html

In particular --
http://ffmpeg.org/doxygen/trunk/doc_2examples_2decoding_encoding_8c-example.html


> Here is what I have tried so far
>
>
>
> void write_frame_to_file(AVFrame* frame, int width, int height, int iframe)
> {
>          FILE* outfile;
>          char filename[32];
>          int y;
>
>          // Open file
>          sprintf(filename, "frame%d.yuv", iframe);
>          outfile = fopen(filename, "wb");
>          if (outfile == NULL) {
>                  return;
>          }
>
>          // Write pixel data
>          for (y = 0; y < height; ++y) {
>                  fwrite(frame->data[0]+y*frame->linesize[0], 1, width*3,
> outfile);

not width * 3, it should be frame->linesize[0] (if you really want to
save it line by line)

And unless the frame pixel format is packed YUV (it's usually planar)
you wouldn't be saving the UV part of the image.  For planar formats
you'll probably want to save all the frame->data planes.

Also, there is no guarantee that the frame data is YUV at all (it could
be BGRA), so you'll probably want to convert the frame to YUV pixel
format.  Take a look at
http://ffmpeg.org/doxygen/trunk/doc_2examples_2filtering_video_8c-example.html 
(or
http://ffmpeg.org/doxygen/trunk/doc_2examples_2scaling_video_8c-example.html 
-- it's probably all you really need).

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user