how to output a media stream using ffmpeg?

user7925034

I am reading a mpeg4 video stream using ffmpeg. I use some of its properties and do some processes using those properties. What I want is to play the opened video using a player like vlc. And then consequently I need to play the output video after processing in order to check whether there is a latency. Is it possible to give the video to a port. So that I can get the video as a input to the vlc player from the specific port.

This is my code up to now. I use MV_generation method to extract features from it and to do a comparison from it.

static int MV_generation(const AVPacket *pkt)
{
    std::vector<unsigned long long> vl = File_read();
    std::hash<string> hash1;
    std::ios_base::app);
    double x_src_val = 0;
    double y_src_val = 0;
    double x_dst_val = 0;
    double y_dst_val = 0;

    int ret = avcodec_send_packet(video_dec_ctx, pkt);
    if (ret < 0) {
        //fprintf(stderr, "Error while sending a packet to the decoder: %s\n", av_err2str(ret));
        return ret;
    }
    video_frame_count++;
    while (ret >= 0){

        ret = avcodec_receive_frame(video_dec_ctx, frame);
        if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
            break;
        }
        else if (ret < 0) {
            return ret;
        }
        if (ret >= 0) {
            AVFrameSideData *sd;
            sd = av_frame_get_side_data(frame, AV_FRAME_DATA_MOTION_VECTORS);

            if (sd) {

                const AVMotionVector *mvs = (const AVMotionVector *)sd->data;

                int size_sd = sd->size;
                //outData << size_sd << endl;

                string str = "", str1, str2, str3, str4;
                for (int i = 0; i < size_sd / sizeof(*mvs); i++) {
                    const AVMotionVector *mv = &mvs[i];

                    int x_src = mv->src_x;
                    int y_src = mv->src_y;
                    int x_dst = mv->dst_x;
                    int y_dst = mv->dst_y;


                    if (x_src != x_dst || y_src != y_dst || x_src > 100 || y_src > 100 || x_dst > 100 || y_dst > 100){
                        str1 = to_string(x_src);
                        str2 = to_string(y_src);
                        str3 = to_string(x_dst);
                        str4 = to_string(y_dst);

                        str = str.append(str1).append(str2).append(str3).append(str4);
                    }
                }

                for (unsigned long long y : vl)
                {
                    // Check if any of the numbers are equal to x
                    if (hash1(str) == y)
                    {
                        cout << "matched frame_no : " << video_frame_count << endl;
                    }
                }
            }
            av_frame_unref(frame);
        }
    }
    outData.close();
    return 0;
}
user7925034

This method can also used once the frame is converted to a mat

int ShowVideo(Mat mRGB, string textOnVideo, string windowName){
    namedWindow(windowName, 1);


Pict_type = frame->pict_type;
//cout << av_get_picture_type_char(Pict_type); //I P or B frame 

if (AV_PICTURE_TYPE_NONE != Pict_type)
{
    namedWindow(windowName, 1);
    mRGB = Mat(dec_ctx->height, dec_ctx->width, CV_8UC3);
    Mat mYUV(dec_ctx->height + dec_ctx->height / 2, dec_ctx->width, CV_8UC1, (void*)buff);
    cvtColor(mYUV, mRGB, CV_YUV2RGB_YV12, 3);

    putText(mRGB, textOnVideo,
        Point(100, 100), FONT_HERSHEY_PLAIN, 1, Scalar(0, 0, 255, 255));


    imshow(windowName, mRGB);
    waitKey(1);
}
return 0;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Output RTSP stream with ffmpeg

From Dev

How to stream a local video to webcam using ffmpeg?

From Dev

How to limit output filesize of ffmpeg input stream to 10 megabytes

From Dev

c# - How to asynchronously stream output from ffmpeg

From Dev

How to compress output video with trim using FFMPEG

From Dev

ffmpeg: chain of multiple filter_complex, re-using intermediate output stream

From Dev

Trim video and concatenate using ffmpeg - getting "Non-monotonous DTS in output stream" errors

From Dev

output pdf using stream

From Dev

Using the ffmpeg to extract video stream

From Dev

Using the ffmpeg to extract video stream

From Dev

Using ffmpeg to convert stream with delayed audio stream

From Dev

How to pipe the output ffmpeg?

From Dev

FFMPEG: How to chose a stream from all stream

From Dev

FFMPEG: How to chose a stream from all stream

From Dev

How to start/stop FFMPEG stream?

From Dev

Android Error While Using FFMPEG Commands - error while opening encoder for output stream - maybe incorrect parameters such as bit_rate etc

From Dev

Using CSVHelper to output stream to browser

From Dev

How to stream and download a media from local storage using Android's VideoView?

From Dev

How to record remote video using webrtc or media stream from video tag

From Dev

How to send ffmpeg output to framebuffer?

From Dev

stream webcam using ffmpeg and live555

From Dev

Encoding a live stream of bitmaps using FFMPEG

From Dev

Encoding a live stream of bitmaps using FFMPEG

From Dev

Conditionally encode or copy audio stream using FFMpeg

From Dev

Live stream prerecorded footage to YouTube using FFMPEG

From Dev

How to connect a input stream to a output stream in Java?

From Dev

How to extract('demux') from 'mp4' video to get the encoded data(or elementary stream) using ffmpeg?

From Dev

How to set custom handler_name metadata for subtitle stream using FFMPEG

From Dev

How can I extract keyframe and p-frame from stream with single command using ffmpeg

Related Related

  1. 1

    Output RTSP stream with ffmpeg

  2. 2

    How to stream a local video to webcam using ffmpeg?

  3. 3

    How to limit output filesize of ffmpeg input stream to 10 megabytes

  4. 4

    c# - How to asynchronously stream output from ffmpeg

  5. 5

    How to compress output video with trim using FFMPEG

  6. 6

    ffmpeg: chain of multiple filter_complex, re-using intermediate output stream

  7. 7

    Trim video and concatenate using ffmpeg - getting "Non-monotonous DTS in output stream" errors

  8. 8

    output pdf using stream

  9. 9

    Using the ffmpeg to extract video stream

  10. 10

    Using the ffmpeg to extract video stream

  11. 11

    Using ffmpeg to convert stream with delayed audio stream

  12. 12

    How to pipe the output ffmpeg?

  13. 13

    FFMPEG: How to chose a stream from all stream

  14. 14

    FFMPEG: How to chose a stream from all stream

  15. 15

    How to start/stop FFMPEG stream?

  16. 16

    Android Error While Using FFMPEG Commands - error while opening encoder for output stream - maybe incorrect parameters such as bit_rate etc

  17. 17

    Using CSVHelper to output stream to browser

  18. 18

    How to stream and download a media from local storage using Android's VideoView?

  19. 19

    How to record remote video using webrtc or media stream from video tag

  20. 20

    How to send ffmpeg output to framebuffer?

  21. 21

    stream webcam using ffmpeg and live555

  22. 22

    Encoding a live stream of bitmaps using FFMPEG

  23. 23

    Encoding a live stream of bitmaps using FFMPEG

  24. 24

    Conditionally encode or copy audio stream using FFMpeg

  25. 25

    Live stream prerecorded footage to YouTube using FFMPEG

  26. 26

    How to connect a input stream to a output stream in Java?

  27. 27

    How to extract('demux') from 'mp4' video to get the encoded data(or elementary stream) using ffmpeg?

  28. 28

    How to set custom handler_name metadata for subtitle stream using FFMPEG

  29. 29

    How can I extract keyframe and p-frame from stream with single command using ffmpeg

HotTag

Archive