Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you provide an example of encoding image sequence into video file #139

Open
zjd1988 opened this issue Jun 26, 2024 · 1 comment
Open

Comments

@zjd1988
Copy link

zjd1988 commented Jun 26, 2024

wonderful work!!
Now I need to encode image sequence into file,I modify code from https://github.com/h4tr3d/avcpp/blob/master/example/api2-samples/api2-scale-video.cpp

but get errors:

....
[avi @ 0x5555558d0600] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 12 >= 12
[avi @ 0x5555558d0600] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 13 >= 13
[avi @ 0x5555558d0600] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 14 >= 14
....

my codes

            // use opencv read image files
            cv::Mat frame = cv::imread(file_name);
            std::string av_format = "bgr24";
            int frame_h = frame.rows;
            int frame_w = frame.cols;
            int frame_ch = frame.channels();
            int frame_size = frame_h * frame_w * frame_ch;
            const uint8_t* frame_data = frame.data;
            av::VideoFrame video_frame(frame_data, frame_size, av::PixelFormat(av_format), frame_w, frame_h);
            // convert bgr24 frame to yuv420p
            av::VideoFrame convert_frame = m_rescaler->rescale(video_frame, ec);
           
           // encode frame to packet
           opkt = m_venc->encode(convert_frame, ec);

           opkt.setStreamIndex(0);

           // error occur
           m_octx->writePacket(opkt, ec);

@h4tr3d
Copy link
Owner

h4tr3d commented Jun 26, 2024

Just point Timebase and PTS.

Simplest way, set Timebase to the value inverted to required FPS, for example 1/60 and use sequential counter for the frames: 1, 2, 3, 4, ..., n. So, each frame time can be simple calculated in seconds: seq * timebase = n * 1 / 60.

Set timebase and PTS for the video_frame.

Refer to:

Set same timebase for the Encoder too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants