[Libav-user] (no subject)

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

[Libav-user] (no subject)

Slaus
Trying to read .mkv file file and write it to .bmp, but resulting .bmp is black-and-white and consists of multiple mini-images of what supposed to be written:

int main()
{
    av_register_all();
    avformat_network_init();
    avfilter_register_all();

    //crashes on -Ofast without =NULL initialization:
    AVFormatContext * format = NULL;
    if ( avformat_open_input( & format, VIDEO_FILE, NULL, NULL ) != 0 ) {
        cerr << "Could not open file " << VIDEO_FILE << endl;
        return -1;
    }

    // Retrieve stream information
    if ( avformat_find_stream_info( format, NULL ) < 0) {
        cerr << "avformat_find_stream_info() failed." << endl;
        return -1;
    }
    av_dump_format( format, 0, VIDEO_FILE, false );
   
    AVCodec * video_dec = (AVCodec*)1;
    AVCodec * audio_dec = (AVCodec*)1;
    const auto video_stream_index = av_find_best_stream( format, AVMEDIA_TYPE_VIDEO, -1, -1, & video_dec, 0 );
    const auto audio_stream_index = av_find_best_stream( format, AVMEDIA_TYPE_AUDIO, -1, -1, & audio_dec, 0 );
    if ( video_stream_index < 0 ) {
        cerr << "Failed to find video stream." << endl;
        return -1;
    }
    if ( audio_stream_index < 0 ) {
        cerr << "Failed to find audio stream." << endl;
        return -1;
    }

    AVCodecParameters * videoParams = format->streams[ video_stream_index ]->codecpar;
    cout << "Having " << videoParams->width << " | " << videoParams->height << " video." << endl;
   
    av_read_play( format );

    // create decoding context
    AVCodecContext * video_ctx = avcodec_alloc_context3( video_dec );
    AVCodecContext * audio_ctx = avcodec_alloc_context3( audio_dec );
    if ( ! video_ctx || ! audio_ctx ) {
        cerr << "Failed to avcodec_alloc_context3()" << endl;
        return -1;
    }
    if ( video_dec->capabilities & AV_CODEC_CAP_TRUNCATED ) video_ctx->flags |= AV_CODEC_FLAG_TRUNCATED; // we do not send complete frames
   
    /* For some codecs, such as msmpeg4 and mpeg4, width and height
       MUST be initialized there because this information is not
       available in the bitstream. */
 
    avcodec_parameters_to_context( video_ctx, format->streams[ video_stream_index ]->codecpar );
    avcodec_parameters_to_context( audio_ctx, format->streams[ audio_stream_index ]->codecpar );
    if ( avcodec_open2( video_ctx, video_dec, NULL ) < 0 ) {
        cout << "Failed to open video decoder." << endl;
        return -1;
    }
    if ( avcodec_open2( audio_ctx, audio_dec, NULL ) < 0 ) {
        cout << "Failed to open audio decoder." << endl;
        return -1;
    }
   
    uint8_t* picture_buffer = (uint8_t*) (av_malloc( avpicture_get_size( AV_PIX_FMT_RGB24 , videoParams->width, videoParams->height ) ));
    AVFrame* picture = av_frame_alloc();
    avpicture_fill( (AVPicture *) picture, picture_buffer, AV_PIX_FMT_RGB24, video_ctx->width, video_ctx->height );
   
    AVPacket packet;
    av_init_packet( & packet );
   
    int cnt = 0;
    while ( av_read_frame( format, & packet ) >= 0 && cnt < 10 ) {
        if ( packet.stream_index == video_stream_index ) {
            int check;
            const auto result = avcodec_decode_video2( video_ctx, picture, & check, & packet );
            cout << "Bytes decoded " << result << " check " << check << endl;
           
            std::string name = "debug/av/";
            name += std::to_string( cnt ) + ".bmp";
            cout << "Writing frame " << name << " with linesize " << picture->linesize[0] << " ..." << endl;
            write_bmp( (uint8_t*) picture->data, videoParams->width, videoParams->height, name.c_str() );
           
            av_frame_unref( picture );
           
            ++ cnt;
        }
        else if ( packet.stream_index == audio_stream_index ) {
            cout << "Sound packet" << endl;
        }
        av_free_packet( & packet );
        av_init_packet( & packet );
    }
}

How can I fix it? Thanks in advance.

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

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: (no subject)

Carl Eugen Hoyos-2
Am Di., 10. März 2020 um 07:25 Uhr schrieb Slav <[hidden email]>:
>
> Trying to read .mkv file file and write it to .bmp, but resulting .bmp is black-and-white and consists of multiple mini-images of what supposed to be written:

(Without looking at your code)
Are there three mini-images of different size?
Then you writing yuv420p but bmp expects rgb

Carl Eugen
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: (no subject)

Slaus
Thank you for your answer!
It is exactly so: 3 smaller images in the middle and even smaller and more below.
How can I convert it to RGB (24 bits)? And overall, how can I always get RGB images from any video file I open?

Thanks in advance!

вт, 10 мар. 2020 г. в 14:27, Carl Eugen Hoyos <[hidden email]>:
Am Di., 10. März 2020 um 07:25 Uhr schrieb Slav <[hidden email]>:
>
> Trying to read .mkv file file and write it to .bmp, but resulting .bmp is black-and-white and consists of multiple mini-images of what supposed to be written:

(Without looking at your code)
Are there three mini-images of different size?
Then you writing yuv420p but bmp expects rgb

Carl Eugen
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

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

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: (no subject)

Carl Eugen Hoyos-2
Am Di., 10. März 2020 um 15:41 Uhr schrieb Slav <[hidden email]>:
>
> Thank you for your answer!
> It is exactly so: 3 smaller images in the middle and even smaller and more below.

Maybe not yuv420p but probably the wrong pix_fmt

> How can I convert it to RGB (24 bits)? And overall, how can I always get RGB images from any video file I open?

There is a filtering / scaling example in doc/examples (the scale filter is
able to do pix_fmt conversion).

Please find out what top-posting means and avoid it here.

Carl Eugen
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: (no subject)

Slaus
I hope I managed to avoid top-posting in gmail ^^

Trying to convert it to RGB with sws_scale(), but can't properly provide it with AVFrames. Here is 3 different ways I try to create AVFrames: https://paste.ubuntu.com/p/fdqFNVpJBM/
What could be the problem? Thanks in advance!

ср, 11 мар. 2020 г. в 03:34, Carl Eugen Hoyos <[hidden email]>:
Am Di., 10. März 2020 um 15:41 Uhr schrieb Slav <[hidden email]>:
>
> Thank you for your answer!
> It is exactly so: 3 smaller images in the middle and even smaller and more below.

Maybe not yuv420p but probably the wrong pix_fmt

> How can I convert it to RGB (24 bits)? And overall, how can I always get RGB images from any video file I open?

There is a filtering / scaling example in doc/examples (the scale filter is
able to do pix_fmt conversion).

Please find out what top-posting means and avoid it here.

Carl Eugen
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

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

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: (no subject)

Christopher Snowhill
On Wed, 2020-03-11 at 10:12 +0400, Slav wrote:
> I hope I managed to avoid top-posting in gmail ^^

Nope, you didn't. Top posting, since you apparently didn't bother to
look it up, means replying to a message by typing your reply above the
quoted original message. GMail makes this really easy to do, since it
even completely hides the original message by default.

Apple Mail on mobile devices makes it almost impossible to not do,
since it likes to make deleting parts of the quoted message, or typing
in the middle of the quote block, a painful process.


> Trying to convert it to RGB with sws_scale(), but can't properly
> provide it with AVFrames. Here is 3 different ways I try to create
> AVFrames: https://paste.ubuntu.com/p/fdqFNVpJBM/
> What could be the problem? Thanks in advance!
>
> ср, 11 мар. 2020 г. в 03:34, Carl Eugen Hoyos <[hidden email]>:
> > Am Di., 10. März 2020 um 15:41 Uhr schrieb Slav <[hidden email]>
> > :
> > >
> > > Thank you for your answer!
> > > It is exactly so: 3 smaller images in the middle and even smaller
> > and more below.
> >
> > Maybe not yuv420p but probably the wrong pix_fmt
> >
> > > How can I convert it to RGB (24 bits)? And overall, how can I
> > always get RGB images from any video file I open?
> >
> > There is a filtering / scaling example in doc/examples (the scale
> > filter is
> > able to do pix_fmt conversion).
> >
> > Please find out what top-posting means and avoid it here.

I think you'll find that most modern web mail silos like GMail and
Exchange, and mail clients like Windows Mail and Apple Mail, especially
on mobile devices, make it darn near impossible to do anything but top
posting. But I guess sane formatting is worth relegating discussion to
users of what are effectively niche clients.

For instance, Evolution, from the Gnome desktop environment, lets me
bottom post, and also kindly offers to let me downgrade a message to
plaintext before replying to it.

> >
> > Carl Eugen
> > _______________________________________________
> > Libav-user mailing list
> > [hidden email]
> > https://ffmpeg.org/mailman/listinfo/libav-user
> >
> > To unsubscribe, visit link above, or email
> > [hidden email] with subject "unsubscribe".
>
> _______________________________________________
> Libav-user mailing list
> [hidden email]
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".

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

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: (no subject)

Slaus
On Wed, 2020-03-11 at 00:58 -0700, [hidden email] wrote:

> On Wed, 2020-03-11 at 10:12 +0400, Slav wrote:
> > I hope I managed to avoid top-posting in gmail ^^
>
> Nope, you didn't. Top posting, since you apparently didn't bother to
> look it up, means replying to a message by typing your reply above
> the
> quoted original message. GMail makes this really easy to do, since it
> even completely hides the original message by default.
>
> Apple Mail on mobile devices makes it almost impossible to not do,
> since it likes to make deleting parts of the quoted message, or
> typing
> in the middle of the quote block, a painful process.
>
>
> > Trying to convert it to RGB with sws_scale(), but can't properly
> > provide it with AVFrames. Here is 3 different ways I try to create
> > AVFrames: https://paste.ubuntu.com/p/fdqFNVpJBM/
> > What could be the problem? Thanks in advance!
> >
> > ср, 11 мар. 2020 г. в 03:34, Carl Eugen Hoyos <[hidden email]>:
> > > Am Di., 10. März 2020 um 15:41 Uhr schrieb Slav <
> > > [hidden email]>
> > > :
> > > > Thank you for your answer!
> > > > It is exactly so: 3 smaller images in the middle and even
> > > > smaller
> > > and more below.
> > >
> > > Maybe not yuv420p but probably the wrong pix_fmt
> > >
> > > > How can I convert it to RGB (24 bits)? And overall, how can I
> > > always get RGB images from any video file I open?
> > >
> > > There is a filtering / scaling example in doc/examples (the scale
> > > filter is
> > > able to do pix_fmt conversion).
> > >
> > > Please find out what top-posting means and avoid it here.
>
> I think you'll find that most modern web mail silos like GMail and
> Exchange, and mail clients like Windows Mail and Apple Mail,
> especially
> on mobile devices, make it darn near impossible to do anything but
> top
> posting. But I guess sane formatting is worth relegating discussion
> to
> users of what are effectively niche clients.
>
> For instance, Evolution, from the Gnome desktop environment, lets me
> bottom post, and also kindly offers to let me downgrade a message to
> plaintext before replying to it.
>
> > > Carl Eugen
> > > _______________________________________________
> > > Libav-user mailing list
> > > [hidden email]
> > > https://ffmpeg.org/mailman/listinfo/libav-user
> > >
> > > To unsubscribe, visit link above, or email
> > > [hidden email] with subject "unsubscribe".
> >
> > _______________________________________________
> > Libav-user mailing list
> > [hidden email]
> > https://ffmpeg.org/mailman/listinfo/libav-user
> >
> > To unsubscribe, visit link above, or email
> > [hidden email] with subject "unsubscribe".
>
> _______________________________________________
> Libav-user mailing list
> [hidden email]
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".


I just don't wanna look ignorant, so have to justify myself ^^ : I
found this post about gmail top-posting:
https://webapps.stackexchange.com/questions/18660/set-up-gmail-to-place-the-quoted-text-on-top-of-my-reply-for-bottom-posting
- 22 likes with no satisfying answer, then got to this one:
https://stackoverflow.com/questions/21394987/gmail-how-do-i-not-top-post-in-gmail-replies
where it says you have to preselect any text before hitting "Reply"
button, which I did and immediately after posting did notice that I
failed to avoid top-posting ^^ (you're right about gmail completely
hiding previous content so it's hard to see where you type: above or
below it).
So, currently posting from within Evolution (it's actually pretty lit)
to see if it's gonna help, sorry for experimenting on you guys ^^

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

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".