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

FFMPEGFrameRecorder example #410

Closed
rpgomes opened this issue May 18, 2016 · 11 comments
Closed

FFMPEGFrameRecorder example #410

rpgomes opened this issue May 18, 2016 · 11 comments
Labels

Comments

@rpgomes
Copy link

rpgomes commented May 18, 2016

Hello,

I'm experiment to use FFMPEGFrameRecorder to record the stream that I capture to a file,
the requirement is to make a mjpeg file,
but when I try to start the recording I get an

org.bytedeco.javacv.FrameRecorder$Exception: avcodec_open2() error -22: Could not open video codec.

my code:

FFmpegFrameRecorder ffr = new FFmpegFrameRecorder("myFile.mp4",dim.getWidth(),dim.getHeight(), 0);
            ffr.setFormat("mjpeg");
            ffr.setVideoCodec(8);//MJPEG I think
            try {
                ffr.start();
            } catch (org.bytedeco.javacv.FrameRecorder.Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

What I'm doing wrong, can someone give me some parametrization pointers?

@saudet
Copy link
Member

saudet commented May 19, 2016

I don't think there is such a thing as the "mjpeg" format. It's not in the list returned by ffmpeg -formats anyway, so call av_oformat_next() in a loop to make sure it's in the list.

@saudet saudet closed this as completed May 19, 2016
@saudet
Copy link
Member

saudet commented May 19, 2016

Oh, actually it's in the list. I get this error message in the log:

Error: [mjpeg @ 0x7f56980ac200] Specified pixel format yuv420p is invalid or not supported

So simply call setPixelFormat() with a supported pixel format such as AV_PIX_FMT_YUVJ420P before start().

@rpgomes
Copy link
Author

rpgomes commented May 19, 2016

Ok,

with the setPixelFormat(avutil.AV_PIX_FMT_YUVJ420P);
I managed to start.

I'm making some mjpeg experiemnts, and I configured an FFserver and test with success with the ffmpeg directly:

ffmpeg -rtsp_transport tcp -i "rtsp://root:pass@IP/axis-media/media.amp" -vcodec mjpeg http://ffserverIP:8090/feed1.ffm

and managed to play in an html< IMG> tag

I'm trying to do the same with FfmpegFrameRecorder:
my code:

ffr = new FFmpegFrameRecorder("http://" + "FFSERVER_IP"  + ":" + 8090 + "/feed1.ffm",dim.getWidth(),dim.getHeight(), 0);
            ffr.setFormat("mjpeg");
            ffr.setVideoCodec(8);//MJPEG
            ffr.setPixelFormat(avutil.AV_PIX_FMT_YUVJ420P);

            try {
                ffr.start();
            } catch (org.bytedeco.javacv.FrameRecorder.Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

this return this output:

Output #0, mjpeg, to 'http://192.168.0.69:8090/feed1.ffm':
    Stream #0:0: Video: mjpeg, yuvj420p, 352x288, q=2-31, 400 kb/s, 5 tbn, 5 tbc

but when I record the frame:

try {
                            ffr.record(f);
                        } catch (org.bytedeco.javacv.FrameRecorder.Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }

I get this exception:

org.bytedeco.javacv.FrameRecorder$Exception: av_write_frame() error -10054 while
 writing video frame.
        at rg.bytedeco.javacv.FFmpegFrameRecorder.recordImage(FFmpegFrameRecorder.java:800)
        at org.bytedeco.javacv.FFmpegFrameRecorder.record(FFmpegFrameRecorder.java:686)
        at org.bytedeco.javacv.FFmpegFrameRecorder.record(FFmpegFrameRecorder.java:679)

Did I need to make more configuration in FFMPEGFrameRecorder?

@rpgomes rpgomes changed the title FFMPEGFrameGrabber example FFMPEGFrameRecorder example May 19, 2016
@saudet
Copy link
Member

saudet commented May 19, 2016

Check the log, it's going to contain more information.

@saudet
Copy link
Member

saudet commented May 19, 2016

BTW, issue #267 might be related.

@rpgomes
Copy link
Author

rpgomes commented May 19, 2016

Sorry I didn't understand what log should I check ? and where is it?
the log I post was from the JVM

@saudet
Copy link
Member

saudet commented May 19, 2016

What do you get as output after the following?

Output #0, mjpeg, to 'http://192.168.0.69:8090/feed1.ffm':
    Stream #0:0: Video: mjpeg, yuvj420p, 352x288, q=2-31, 400 kb/s, 5 tbn, 5 tbc

@rpgomes
Copy link
Author

rpgomes commented May 19, 2016

That is all I'm getting as output from javacv when I making the ffmpeframerecorder.start().

Then I get the error on recording the frame.

using ffmpeg directly I get this output:

Output #0, ffm, to 'http://192.168.0.69:8090/feed1.ffm':
  Metadata:
    title           : Media Presentation
    creation_time   : 2016-05-19 12:25:39
    encoder         : Lavf57.3.100
    Stream #0:0: Video: mjpeg, yuvj420p(pc), 352x288 [SAR 16:11 DAR 16:9], q=2-3
1, 64 kb/s, 25 fps, 1000k tbn, 5 tbc
    Metadata:
      encoder         : Lavc57.5.100 mjpeg
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))

@saudet
Copy link
Member

saudet commented May 19, 2016

So, you want to use the ffm format, right? You're not going to get that if you call setFormat("mjpeg")...

@rpgomes
Copy link
Author

rpgomes commented May 19, 2016

yep that make the trick,
you're the best :)

Thanks

@saudet
Copy link
Member

saudet commented Mar 24, 2019

FYI, if the ffmpeg program is sufficient, with commit bytedeco/javacpp-presets@13ffffd it now gets bundled and can be used easily from Java.

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

No branches or pull requests

2 participants