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

Right way to implement overlay filter #945

Closed
DeKinci opened this issue Mar 21, 2018 · 112 comments
Closed

Right way to implement overlay filter #945

DeKinci opened this issue Mar 21, 2018 · 112 comments
Labels

Comments

@DeKinci
Copy link

DeKinci commented Mar 21, 2018

I'm currently working on adding an overlay image on top of the video.
It is clear, how to do it on bare FFMpeg, but what is the right way to provide an image for the FFMpegFrameFilter for an overlay filter?
Is it possible to write there -i path/to/img.jpg -filter_complex "[0][1]overlay"? Or there is another way?
And what is the shortcut for a video stream (0 or 1 in this case)?

I know, that it sounds more like a StackOverflow question but it looks like it is impossible to get a reply on a JavaCV topic there

@DeKinci
Copy link
Author

DeKinci commented Mar 21, 2018

So I used movie filter and now string looks like this: movie=path/to/img.jpg[img];[0][img]overlay and all i got is just rotated vertically and tripled image

@saudet
Copy link
Member

saudet commented Mar 21, 2018 via email

@DeKinci
Copy link
Author

DeKinci commented Mar 21, 2018

Yes, the image is transformed exactly like that. I will adjust it and share the result.

But another problem is that the picture is not presented in the final video in any way (not transformed, not tripled, just no image).
Now I use [in] shortcut to specify the input stream, [0] refused to work. I do not specify [out] explicitly, because it is not necessary in the common ffmpeg and it also causes crash.
The path that I provide to the overlay filter is a full path /storage/emulated/0/Appname/img.png
When I only use movie=path filter it also crashes

By the way, maybe it would be useful to extract some frequently used filters into classes and also provide API for constructing a filters graph?

@saudet
Copy link
Member

saudet commented Mar 21, 2018 via email

@saudet
Copy link
Member

saudet commented Mar 22, 2018

BTW, this sounds like a duplicate of issue #667 and I'm pretty sure that's fixed by adjusting the pixel formats accordingly. If this isn't the case though, please let me know.

@DeKinci
Copy link
Author

DeKinci commented Mar 22, 2018

Firstly, I tested ffmpeg on a pc with the following command and it worked fine: ffmpeg -i video.mp4 -vf movie=img.png[img];[in][img]overlay[out] output.mp4 so it is possible to assert that filter string is OK.

Next, setting pixelFormat in Recorder.record didn't actually help, but settings right pixelFormat to Filter solved the problem of tripled and turned video (it is not necessary to specify format in recorder).

Now filter's setup looks like this:

filter = new FFmpegFrameFilter("movie=" + path + "[img];[in][img]overlay[out]", imageWidth, imageHeight);
filter.setPixelFormat(avutil.AV_PIX_FMT_YUV420P);
filter.start();

The path is specified correctly and looks like /storage/emulated/0/AppName/test.jpg. I tried both jpg and png formats. When I specify the wrong path e.g. /storage/emulated/0/nothing/test.jpg it crashes with the following error:

org.bytedeco.javacv.FrameFilter$Exception: avfilter_graph_create_filter(): Cannot create buffer source.
     at org.bytedeco.javacv.FFmpegFrameFilter.startUnsafe(FFmpegFrameFilter.java:191)

So the path is also OK.

BUT there is still no image on the final video!
The way I enque and get frames is like this:

((ByteBuffer) frame.image[0].position(0)).put(bytes);
filterManager.put(frame);

Frame edited = filterManager.get();
if (edited != null) {
    //Recording stuff here
}

where filterManager just pushs and pulls frames in try-catch to the filter.

I tried to add an offset to the image in case if it is outside of the screen: [in][img]overlay=x=200:y=200[out] but this also didn't helped

@saudet
Copy link
Member

saudet commented Mar 22, 2018

Maybe we could get more information about what is happening by increasing the log verbosity?

@saudet
Copy link
Member

saudet commented Mar 22, 2018

Anyway, if you could call av_log_set_level(AV_LOG_DEBUG) and post the output of that after processing for 1 or 2 frames, it should help debug this. Thanks!

@DeKinci
Copy link
Author

DeKinci commented Mar 23, 2018

av_log_set_level(AV_LOG_DEBUG) didn't worked, as well as setting another levels. There is no output related to anything except the app. I call it before I call any javaCV's method.
Also, I tried to switch overlay layers from [in][img] to [img][in] and got black frames result and also tried to input mp4 video as movie instead of a pic and result is the same as with the picture

@saudet
Copy link
Member

saudet commented Mar 24, 2018

Also make sure to call FFmpegLogCallback.set() if you don't see anything on the console like that.

@DeKinci
Copy link
Author

DeKinci commented Mar 25, 2018

Thanks! I got this for overlaying video (it looks same as image):

03-25 03:08:21.848 3112-3156/com.domain.appname I/System.out: detected 4 logical cores
03-25 03:08:21.849 3112-3156/com.domain.appname I/System.out: [in @ 0xe86adb40] Setting 'video_size' to value '1280x720'
03-25 03:08:21.849 3112-3156/com.domain.appname I/System.out: [in @ 0xe86adb40] Setting 'pix_fmt' to value '0'
03-25 03:08:21.849 3112-3156/com.domain.appname I/System.out: [in @ 0xe86adb40] Setting 'time_base' to value '1/30'
03-25 03:08:21.849 3112-3156/com.domain.appname I/System.out: [in @ 0xe86adb40] Setting 'pixel_aspect' to value '1/1'
03-25 03:08:21.850 3112-3156/com.domain.appname I/System.out: [in @ 0xe86adb40] w:1280 h:720 pixfmt:yuv420p tb:1/30 fr:0/1 sar:1/1 sws_param:
03-25 03:08:21.850 3112-3156/com.domain.appname I/System.out: [Parsed_movie_0 @ 0xe86add20] Setting 'filename' to value '/storage/emulated/0/AppName/test.mp4'
03-25 03:08:21.851 3112-3156/com.domain.appname I/System.out: [NULL @ 0xd924b200] Opening '/storage/emulated/0/AppName/test.mp4' for reading
03-25 03:08:21.851 3112-3156/com.domain.appname I/System.out: [file @ 0xd9adbe70] Setting default whitelist 'file,crypto'
03-25 03:08:21.851 3112-3156/com.domain.appname I/System.out: [mov,mp4,m4a,3gp,3g2,mj2 @ 0xd924b200] Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=2048 and score=100
03-25 03:08:21.851 3112-3156/com.domain.appname I/System.out: [mov,mp4,m4a,3gp,3g2,mj2 @ 0xd924b200] ISO: File Type Major Brand: isom
03-25 03:08:21.852 3112-3156/com.domain.appname I/System.out: [mov,mp4,m4a,3gp,3g2,mj2 @ 0xd924b200] Unknown dref type 0x206c7275 size 12
03-25 03:08:21.852 3112-3156/com.domain.appname I/System.out: [mov,mp4,m4a,3gp,3g2,mj2 @ 0xd924b200] Processing st: 0, edit list 0 - media time: -1, duration: 1014
03-25 03:08:21.852 3112-3156/com.domain.appname I/System.out: [mov,mp4,m4a,3gp,3g2,mj2 @ 0xd924b200] Processing st: 0, edit list 1 - media time: 0, duration: 371712
03-25 03:08:21.852 3112-3156/com.domain.appname I/System.out: [mov,mp4,m4a,3gp,3g2,mj2 @ 0xd924b200] drop a frame at curr_cts: 371712 @ 422
03-25 03:08:21.853 3112-3156/com.domain.appname I/System.out: [mov,mp4,m4a,3gp,3g2,mj2 @ 0xd924b200] Unknown dref type 0x206c7275 size 12
03-25 03:08:21.853 3112-3156/com.domain.appname I/System.out: [mov,mp4,m4a,3gp,3g2,mj2 @ 0xd924b200] Processing st: 1, edit list 0 - media time: 1024, duration: 1073129
03-25 03:08:21.853 3112-3156/com.domain.appname I/System.out: [mov,mp4,m4a,3gp,3g2,mj2 @ 0xd924b200] drop a frame at curr_cts: 0 @ 0
03-25 03:08:21.853 3112-3156/com.domain.appname I/System.out: [mov,mp4,m4a,3gp,3g2,mj2 @ 0xd924b200] Before avformat_find_stream_info() pos: 1693560 bytes read:48607 seeks:1 nb_streams:2
03-25 03:08:21.862 3112-3156/com.domain.appname I/System.out: [mov,mp4,m4a,3gp,3g2,mj2 @ 0xd924b200] demuxer injecting skip 1024 / discard 0
03-25 03:08:21.862 3112-3156/com.domain.appname I/System.out: [aac @ 0xe86cc400] skip 1024 / discard 0 samples due to side data
03-25 03:08:21.863 3112-3156/com.domain.appname I/System.out: [mov,mp4,m4a,3gp,3g2,mj2 @ 0xd924b200] All info found
03-25 03:08:21.864 3112-3156/com.domain.appname I/System.out: [mov,mp4,m4a,3gp,3g2,mj2 @ 0xd924b200] After avformat_find_stream_info() pos: 30647 bytes read:81375 seeks:2 frames:5
03-25 03:08:21.864 3112-3156/com.domain.appname I/System.out: [Parsed_movie_0 @ 0xe86add20] seek_point:0 format_name:(null) file_name:/storage/emulated/0/AppName/test.mp4 stream_index:-1
03-25 03:08:21.865 3112-3156/com.domain.appname I/System.out: [auto_scaler_0 @ 0xe86adcc0] w:iw h:ih flags:'bilinear' interl:0
03-25 03:08:21.865 3112-3156/com.domain.appname I/System.out: [Parsed_overlay_1 @ 0xe86ade40] auto-inserting filter 'auto_scaler_0' between the filter 'in' and the filter 'Parsed_overlay_1'
03-25 03:08:21.865 3112-3156/com.domain.appname I/System.out: [AVFilterGraph @ 0xd90b5900] query_formats: 4 queried, 2 merged, 1 already done, 0 delayed
03-25 03:08:21.865 3112-3156/com.domain.appname I/System.out: [auto_scaler_0 @ 0xe86adcc0] w:1280 h:720 fmt:yuv420p sar:1/1 -> w:1280 h:720 fmt:yuva420p sar:1/1 flags:0x2
03-25 03:08:21.865 3112-3156/com.domain.appname I/System.out: [Parsed_overlay_1 @ 0xe86ade40] main w:1280 h:720 fmt:yuv420p overlay w:1280 h:720 fmt:yuva420p
03-25 03:08:21.865 3112-3156/com.domain.appname I/System.out: [Parsed_overlay_1 @ 0xe86ade40] [framesync @ 0xe11436a0] Selected 1/15360 time base
03-25 03:08:21.865 3112-3156/com.domain.appname I/System.out: [Parsed_overlay_1 @ 0xe86ade40] [framesync @ 0xe11436a0] Sync level 2
03-25 03:08:21.939 3112-3156/com.domain.appname I/System.out: [libx264 @ 0xe86ccc00] using cpu capabilities: none!
03-25 03:08:21.939 3112-3156/com.domain.appname I/System.out: [libx264 @ 0xe86ccc00] using cpu capabilities: none!
03-25 03:08:21.946 3112-3156/com.domain.appname I/System.out: [libx264 @ 0xe86ccc00] profile Constrained Baseline, level 3.1
03-25 03:08:21.946 3112-3156/com.domain.appname I/System.out: [libx264 @ 0xe86ccc00] profile Constrained Baseline, level 3.1
03-25 03:08:21.946 3112-3156/com.domain.appname I/System.out: [libx264 @ 0xe86ccc00] 264 - core 152 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=4 lookahead_threads=4 sliced_threads=1 slices=4 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=60 keyint_min=6 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=27.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
03-25 03:08:21.946 3112-3156/com.domain.appname I/System.out: [libx264 @ 0xe86ccc00] 264 - core 152 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=4 lookahead_threads=4 sliced_threads=1 slices=4 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=60 keyint_min=6 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=27.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
03-25 03:08:21.999 3112-3156/com.domain.appname I/System.out: [rtmp @ 0xd9adc260] No default whitelist set
03-25 03:08:21.999 3112-3156/com.domain.appname I/System.out: [tcp @ 0xe86ae2c0] No default whitelist set
03-25 03:08:25.022 3112-3156/com.domain.appname I/System.out: [rtmp @ 0xd9adc260] Handshaking...
03-25 03:08:25.050 3112-3156/com.domain.appname I/System.out: [rtmp @ 0xd9adc260] Type answer 3
03-25 03:08:25.050 3112-3156/com.domain.appname I/System.out: [rtmp @ 0xd9adc260] Server version 4.0.0.1
03-25 03:08:25.050 3112-3156/com.domain.appname I/System.out: [rtmp @ 0xd9adc260] Proto = rtmp, path = /live2/qc8s-14g7-q31u-am57, app = live2, fname = qc8s-14g7-q31u-am57
03-25 03:08:25.281 3112-3156/com.domain.appname I/System.out: [rtmp @ 0xd9adc260] Window acknowledgement size = 2500000
03-25 03:08:25.281 3112-3156/com.domain.appname I/System.out: [rtmp @ 0xd9adc260] Max sent, unacked = 10000000
03-25 03:08:25.281 3112-3156/com.domain.appname I/System.out: [rtmp @ 0xd9adc260] New incoming chunk size = 256
03-25 03:08:25.314 3112-3156/com.domain.appname I/System.out: [rtmp @ 0xd9adc260] Releasing stream...
03-25 03:08:25.314 3112-3156/com.domain.appname I/System.out: [rtmp @ 0xd9adc260] FCPublish stream...
03-25 03:08:25.314 3112-3156/com.domain.appname I/System.out: [rtmp @ 0xd9adc260] Creating stream...
03-25 03:08:25.342 3112-3156/com.domain.appname I/System.out: [rtmp @ 0xd9adc260] Sending publish command for 'qc8s-14g7-q31u-am57'
03-25 03:08:25.577 3112-3156/com.domain.appname I/System.out: Output #0, flv, to 'rtmp://a.rtmp.youtube.com/live2/qc8s-14g7-q31u-am57':
03-25 03:08:25.577 3112-3156/com.domain.appname I/System.out: Output #0, flv, to 'rtmp://a.rtmp.youtube.com/live2/qc8s-14g7-q31u-am57':
03-25 03:08:25.577 3112-3156/com.domain.appname I/System.out:   Metadata:
03-25 03:08:25.577 3112-3156/com.domain.appname I/System.out:   Metadata:
03-25 03:08:25.577 3112-3156/com.domain.appname I/System.out:     encoder         : 
03-25 03:08:25.577 3112-3156/com.domain.appname I/System.out:     encoder         : 
03-25 03:08:25.577 3112-3156/com.domain.appname I/System.out: Lavf57.83.100
03-25 03:08:25.577 3112-3156/com.domain.appname I/System.out: Lavf57.83.100
03-25 03:08:25.577 3112-3156/com.domain.appname I/System.out:     Stream #0:0
03-25 03:08:25.577 3112-3156/com.domain.appname I/System.out:     Stream #0:0
03-25 03:08:25.577 3112-3156/com.domain.appname I/System.out: , 0, 1/1000
03-25 03:08:25.577 3112-3156/com.domain.appname I/System.out: : Video: h264 (Constrained Baseline), 1 reference frame ([7][0][0][0] / 0x0007), yuv420p, 1280x720 (0x0), 0/1, q=2-31, 2764 kb/s
03-25 03:08:25.577 3112-3156/com.domain.appname I/System.out: : Video: h264 (Constrained Baseline), 1 reference frame ([7][0][0][0] / 0x0007), yuv420p, 1280x720 (0x0), 0/1, q=2-31, 2764 kb/s
03-25 03:08:25.577 3112-3156/com.domain.appname I/System.out: , 
03-25 03:08:25.577 3112-3156/com.domain.appname I/System.out: , 
03-25 03:08:25.578 3112-3156/com.domain.appname I/System.out: 1k tbn
03-25 03:08:25.578 3112-3156/com.domain.appname I/System.out: 1k tbn
03-25 03:08:25.579 3112-3156/com.domain.appname I/System.out:     Stream #0:1
03-25 03:08:25.579 3112-3156/com.domain.appname I/System.out:     Stream #0:1
03-25 03:08:25.579 3112-3156/com.domain.appname I/System.out: , 0, 1/1000
03-25 03:08:25.579 3112-3156/com.domain.appname I/System.out: : Audio: aac (LC) ([10][0][0][0] / 0x000A), 44100 Hz, stereo, fltp, delay 1024, 128 kb/s
03-25 03:08:25.579 3112-3156/com.domain.appname I/System.out: : Audio: aac (LC) ([10][0][0][0] / 0x000A), 44100 Hz, stereo, fltp, delay 1024, 128 kb/s
03-25 03:08:25.604 3112-3215/com.domain.appname I/System.out: [SWR @ 0xdfa89000] Using s16p internally between filters
03-25 03:08:25.677 3112-3216/com.domain.appname I/System.out: [in @ 0xe86adb40] Changing frame properties on the fly is not supported by all filters.
03-25 03:08:25.677 3112-3216/com.domain.appname I/System.out: [in @ 0xe86adb40] Changing frame properties on the fly is not supported by all filters.
03-25 03:08:25.678 3112-3216/com.domain.appname I/System.out: [auto_scaler_0 @ 0xe86adcc0] w:1280 h:720 fmt:nv21 sar:0/1 -> w:1280 h:720 fmt:yuva420p sar:0/1 flags:0x2

03-25 03:08:25.716 3112-3216/com.domain.appname I/System.out: [in @ 0xe86adb40] Changing frame properties on the fly is not supported by all filters.
03-25 03:08:25.716 3112-3216/com.domain.appname I/System.out: [in @ 0xe86adb40] Changing frame properties on the fly is not supported by all filters.

03-25 03:08:25.770 3112-3216/com.domain.appname I/System.out: [in @ 0xe86adb40] Changing frame properties on the fly is not supported by all filters.
03-25 03:08:25.770 3112-3216/com.domain.appname I/System.out: [in @ 0xe86adb40] Changing frame properties on the fly is not supported by all filters.

...

Where the first part is initialization, and the second are two frames.

@saudet
Copy link
Member

saudet commented Mar 25, 2018 via email

@DeKinci
Copy link
Author

DeKinci commented Mar 25, 2018

Nothing changed

@DeKinci
Copy link
Author

DeKinci commented Mar 25, 2018

Maybe this issue is caused by the same reason as in #232, in the last comment, also it was mentioned in #507. There is nothing about the solution, but it may help to find where the bug appears.

@saudet
Copy link
Member

saudet commented Mar 25, 2018 via email

@DeKinci
Copy link
Author

DeKinci commented Mar 25, 2018

I'm using yuv420, it's sad if it is not supported

@saudet
Copy link
Member

saudet commented Mar 25, 2018 via email

@DeKinci
Copy link
Author

DeKinci commented Mar 26, 2018

I used rgb24 and it didn't helped

@saudet
Copy link
Member

saudet commented Mar 26, 2018

Ok, please post the whole filter command you used and the whole log output again.

@saudet
Copy link
Member

saudet commented Mar 26, 2018

Ah, I might have an answer here:

loop
Specifies how many times to read the stream in sequence. If the value is 0, the stream will be looped infinitely. Default value is "1".

https://ffmpeg.org/ffmpeg-filters.html#movie-1

We should probably use 0 for an image file.

@DeKinci DeKinci closed this as completed Mar 26, 2018
@DeKinci DeKinci reopened this Mar 26, 2018
@DeKinci
Copy link
Author

DeKinci commented Mar 26, 2018

I've tried that already and nothing changed. Also, it works without loop argument on a desktop version

@saudet
Copy link
Member

saudet commented Mar 26, 2018

So it works with JavaCV on Windows, just not on Android? That sounds like a permission issue...

@DeKinci
Copy link
Author

DeKinci commented Mar 26, 2018

No, it works fine on ffmpeg. I didn't try it on a desktop JavaCV, but according to other comments it is not the case.

@DeKinci
Copy link
Author

DeKinci commented Mar 26, 2018

This is a new filter command:

filter = new FFmpegFrameFilter(
                        "movie=" + path + ":format_name=rgb24[img];" +
                                "[in]format=pix_fmts=rgb24[fin];" +
                                "[fin][img]overlay=format=rgb[out]",
                        imageWidth, imageHeight);

And this is log for it:

 detected 4 logical cores
 [in @ 0xd86ea600] Setting 'video_size' to value '1280x720'
 [in @ 0xd86ea600] Setting 'pix_fmt' to value '0'
 [in @ 0xd86ea600] Setting 'time_base' to value '1/30'
 [in @ 0xd86ea600] Setting 'pixel_aspect' to value '1/1'
 [in @ 0xd86ea600] w:1280 h:720 pixfmt:yuv420p tb:1/30 fr:0/1 sar:1/1 sws_param:
 [Parsed_movie_0 @ 0xd86ea7e0] Setting 'filename' to value '/storage/emulated/0/AppName/img.png'
 [Parsed_movie_0 @ 0xd86ea7e0] Setting 'format_name' to value 'rgb24'
 [NULL @ 0xd9274200] Opening '/storage/emulated/0/AppName/img.png' for reading
 [file @ 0xd9b70690] Setting default whitelist 'file,crypto'
 [png_pipe @ 0xd9274200] Format png_pipe probed with size=2048 and score=99
 [png_pipe @ 0xd9274200] Before avformat_find_stream_info() pos: 0 bytes read:32768 seeks:0 nb_streams:1
 [png_pipe @ 0xd9274200] After avformat_find_stream_info() pos: 41290 bytes read:41290 seeks:0 frames:1
 [Parsed_movie_0 @ 0xd86ea7e0] seek_point:0 format_name:rgb24 file_name:/storage/emulated/0/AppName/img.png stream_index:-1
 [Parsed_format_1 @ 0xd86ea840] compat: called with args=[pix_fmts=rgb24]
 [Parsed_format_1 @ 0xd86ea840] Setting 'pix_fmts' to value 'rgb24'
 [Parsed_overlay_2 @ 0xd86ea8a0] Setting 'format' to value 'rgb'
 [auto_scaler_0 @ 0xd86ea900] w:iw h:ih flags:'bilinear' interl:0
 [Parsed_format_1 @ 0xd86ea840] auto-inserting filter 'auto_scaler_0' between the filter 'in' and the filter 'Parsed_format_1'
 [AVFilterGraph @ 0xdcf6d2c0] query_formats: 5 queried, 3 merged, 1 already done, 0 delayed
 [auto_scaler_0 @ 0xd86ea900] w:1280 h:720 fmt:yuv420p sar:1/1 -> w:1280 h:720 fmt:rgb24 sar:1/1 flags:0x2
 [Parsed_overlay_2 @ 0xd86ea8a0] main w:1280 h:720 fmt:rgb24 overlay w:1280 h:720 fmt:rgba
 [Parsed_overlay_2 @ 0xd86ea8a0] [framesync @ 0xe8f4e420] Selected 1/150 time base
 [Parsed_overlay_2 @ 0xd86ea8a0] [framesync @ 0xe8f4e420] Sync level 2
 [libx264 @ 0xdd152c00] using cpu capabilities: none!
 [libx264 @ 0xdd152c00] using cpu capabilities: none!
 [libx264 @ 0xdd152c00] profile Constrained Baseline, level 3.1
 [libx264 @ 0xdd152c00] profile Constrained Baseline, level 3.1
 [libx264 @ 0xdd152c00] 264 - core 152 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=4 lookahead_threads=4 sliced_threads=1 slices=4 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=60 keyint_min=6 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=27.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
 [libx264 @ 0xdd152c00] 264 - core 152 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=4 lookahead_threads=4 sliced_threads=1 slices=4 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=60 keyint_min=6 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=27.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
 [rtmp @ 0xd9b70770] No default whitelist set
 [tcp @ 0xd86eade0] No default whitelist set
 [rtmp @ 0xd9b70770] Handshaking...
 [rtmp @ 0xd9b70770] Type answer 3
 [rtmp @ 0xd9b70770] Server version 4.0.0.1
 [rtmp @ 0xd9b70770] Proto = rtmp, path = /live2/vtmb-yjbw-4hpr-1jjw, app = live2, fname = vtmb-yjbw-4hpr-1jjw
 [rtmp @ 0xd9b70770] Window acknowledgement size = 2500000
 [rtmp @ 0xd9b70770] Max sent, unacked = 10000000
 [rtmp @ 0xd9b70770] New incoming chunk size = 256
 [rtmp @ 0xd9b70770] Releasing stream...
 [rtmp @ 0xd9b70770] FCPublish stream...
 [rtmp @ 0xd9b70770] Creating stream...
 [rtmp @ 0xd9b70770] Sending publish command for 'vtmb-yjbw-4hpr-1jjw'
 Output #0, flv, to 'rtmp://a.rtmp.youtube.com/live2/vtmb-yjbw-4hpr-1jjw':
 Output #0, flv, to 'rtmp://a.rtmp.youtube.com/live2/vtmb-yjbw-4hpr-1jjw':
   Metadata:
   Metadata:
     encoder         : 
     encoder         : 
 Lavf57.83.100
 Lavf57.83.100
     Stream #0:0
     Stream #0:0
 , 0, 1/1000
 : Video: h264 (Constrained Baseline), 1 reference frame ([7][0][0][0] / 0x0007), yuv420p, 1280x720 (0x0), 0/1, q=2-31, 2764 kb/s
 : Video: h264 (Constrained Baseline), 1 reference frame ([7][0][0][0] / 0x0007), yuv420p, 1280x720 (0x0), 0/1, q=2-31, 2764 kb/s
 , 
 , 
 1k tbn
 1k tbn
     Stream #0:1
     Stream #0:1
 , 0, 1/1000
 : Audio: aac (LC) ([10][0][0][0] / 0x000A), 44100 Hz, stereo, fltp, delay 1024, 128 kb/s
 : Audio: aac (LC) ([10][0][0][0] / 0x000A), 44100 Hz, stereo, fltp, delay 1024, 128 kb/s

 [in @ 0xd86ea600] Changing frame properties on the fly is not supported by all filters.
 [in @ 0xd86ea600] Changing frame properties on the fly is not supported by all filters.
 [auto_scaler_0 @ 0xd86ea900] w:1280 h:720 fmt:nv21 sar:0/1 -> w:1280 h:720 fmt:rgb24 sar:0/1 flags:0x2
 [SWR @ 0xdf1e4000] Using s16p internally between filters
 [libx264 @ 0xdd152c00] frame=   0 QP=24.00 NAL=3 Slice:I Poc:0   I:3600 P:0    SKIP:0    size=3929 bytes
 [in @ 0xd86ea600] Changing frame properties on the fly is not supported by all filters.
 [in @ 0xd86ea600] Changing frame properties on the fly is not supported by all filters.
 [libx264 @ 0xdd152c00] frame=   1 QP=20.00 NAL=2 Slice:P Poc:2   I:5    P:15   SKIP:3580 size=471 bytes
 [in @ 0xd86ea600] Changing frame properties on the fly is not supported by all filters.
 [in @ 0xd86ea600] Changing frame properties on the fly is not supported by all filters.
 [libx264 @ 0xdd152c00] frame=   2 QP=20.00 NAL=2 Slice:P Poc:4   I:5    P:12   SKIP:3583 size=145 bytes
 [in @ 0xd86ea600] Changing frame properties on the fly is not supported by all filters.
 [in @ 0xd86ea600] Changing frame properties on the fly is not supported by all filters.
 [libx264 @ 0xdd152c00] frame=   3 QP=19.00 NAL=2 Slice:P Poc:6   I:4    P:18   SKIP:3578 size=845 bytes
 [in @ 0xd86ea600] Changing frame properties on the fly is not supported by all filters.
 [in @ 0xd86ea600] Changing frame properties on the fly is not supported by all filters.

@saudet
Copy link
Member

saudet commented Mar 26, 2018

An image scaler is still being inserted, that's strange.

Anyway, if we compare that with a log of the ffmpeg program, I'm sure we'll find the difference pretty quickly. What does the output for the ffmpeg program look like at the same log level?

@DeKinci
Copy link
Author

DeKinci commented Mar 26, 2018

The command is ffmpeg -loglevel debug -i video.mp4 -vf movie=img.png[img];[in][img]overlay[out] output.mp4 (I removed changing formats because it doesn't help and the PC player refused to play video in new format), also the image size is same as the video size.

And the log is

ffmpeg version 3.4.2 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7.3.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libmfx --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Splitting the commandline.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'.
Reading option '-i' ... matched as input url with argument 'video.mp4'.
Reading option '-vf' ... matched as option 'vf' (set video filters) with argument 'movie=img.png[img];[in][img]overlay[out]'.
Reading option 'output.mp4' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option loglevel (set logging level) with argument debug.
Successfully parsed a group of options.
Parsing a group of options: input url video.mp4.
Successfully parsed a group of options.
Opening an input file: video.mp4.
[NULL @ 000001b8977e24a0] Opening 'video.mp4' for reading
[file @ 000001b8978d6dc0] Setting default whitelist 'file,crypto'
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001b8977e24a0] Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=2048 and score=100
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001b8977e24a0] ISO: File Type Major Brand: isom
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001b8977e24a0] Unknown dref type 0x206c7275 size 12
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001b8977e24a0] Processing st: 0, edit list 0 - media time: 0, duration: 2186752
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001b8977e24a0] Unknown dref type 0x206c7275 size 12
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001b8977e24a0] Processing st: 1, edit list 0 - media time: 0, duration: 8201232
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001b8977e24a0] Before avformat_find_stream_info() pos: 31491130 bytes read:130297 seeks:1 nb_streams:2
[h264 @ 000001b8977f4560] nal_unit_type: 7, nal_ref_idc: 3
[h264 @ 000001b8977f4560] nal_unit_type: 8, nal_ref_idc: 3
[h264 @ 000001b8977f4560] nal_unit_type: 5, nal_ref_idc: 3
[h264 @ 000001b8977f4560] Reinit context to 1280x720, pix_fmt: yuv420p
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001b8977e24a0] All info found
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001b8977e24a0] After avformat_find_stream_info() pos: 106237 bytes read:236486 seeks:2 frames:2
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 1970-01-01T00:00:00.000000Z
    encoder         : Lavf53.24.2
  Duration: 00:02:50.86, start: 0.000000, bitrate: 1474 kb/s
    Stream #0:0(und), 1, 1/12800: Video: h264 (Main), 1 reference frame (avc1 / 0x31637661), yuv420p(left), 1280x720 [SAR 1:1 DAR 16:9], 0/1, 1086 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      creation_time   : 1970-01-01T00:00:00.000000Z
      handler_name    : VideoHandler
    Stream #0:1(und), 1, 1/48000: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 383 kb/s (default)
    Metadata:
      creation_time   : 1970-01-01T00:00:00.000000Z
      handler_name    : SoundHandler
Successfully opened the file.
Parsing a group of options: output url output.mp4.
Applying option vf (set video filters) with argument movie=img.png[img];[in][img]overlay[out].
Successfully parsed a group of options.
Opening an output file: output.mp4.
[file @ 000001b8978dd440] Setting default whitelist 'file,crypto'
Successfully opened the file.
detected 8 logical cores
[h264 @ 000001b8978de6c0] nal_unit_type: 7, nal_ref_idc: 3
[h264 @ 000001b8978de6c0] nal_unit_type: 8, nal_ref_idc: 3
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
[graph_1_in_0_1 @ 000001b89942d880] Setting 'time_base' to value '1/48000'
[graph_1_in_0_1 @ 000001b89942d880] Setting 'sample_rate' to value '48000'
[graph_1_in_0_1 @ 000001b89942d880] Setting 'sample_fmt' to value 'fltp'
[graph_1_in_0_1 @ 000001b89942d880] Setting 'channel_layout' to value '0x3f'
[graph_1_in_0_1 @ 000001b89942d880] tb:1/48000 samplefmt:fltp samplerate:48000 chlayout:0x3f
[format_out_0_1 @ 000001b89972bc80] Setting 'sample_fmts' to value 'fltp'
[format_out_0_1 @ 000001b89972bc80] Setting 'sample_rates' to value '96000|88200|64000|48000|44100|32000|24000|22050|16000|12000|11025|8000|7350'
[AVFilterGraph @ 000001b89968b240] query_formats: 4 queried, 9 merged, 0 already done, 0 delayed
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    Last message repeated 1 times
[h264 @ 000001b8978de6c0] nal_unit_type: 5, nal_ref_idc: 3
[h264 @ 000001b8978de6c0] Reinit context to 1280x720, pix_fmt: yuv420p
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    Last message repeated 2 times
[h264 @ 000001b89780fa20] nal_unit_type: 1, nal_ref_idc: 2
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    Last message repeated 2 times
[h264 @ 000001b8978101c0] nal_unit_type: 1, nal_ref_idc: 2
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    Last message repeated 2 times
[h264 @ 000001b897811040] nal_unit_type: 1, nal_ref_idc: 2
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    Last message repeated 2 times
[h264 @ 000001b89780ae20] nal_unit_type: 1, nal_ref_idc: 2
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    Last message repeated 2 times
[h264 @ 000001b89787f000] nal_unit_type: 1, nal_ref_idc: 2
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    Last message repeated 2 times
[h264 @ 000001b89787fe80] nal_unit_type: 1, nal_ref_idc: 2
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    Last message repeated 1 times
[h264 @ 000001b8978811c0] nal_unit_type: 1, nal_ref_idc: 2
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    Last message repeated 1 times
[h264 @ 000001b89787eb40] nal_unit_type: 1, nal_ref_idc: 2
[Parsed_movie_0 @ 000001b899616f20] Setting 'filename' to value 'img.png'
[NULL @ 000001b89b1017e0] Opening 'img.png' for reading
[file @ 000001b899bc6b60] Setting default whitelist 'file,crypto'
[png_pipe @ 000001b89b1017e0] Format png_pipe probed with size=2048 and score=99
[png_pipe @ 000001b89b1017e0] Before avformat_find_stream_info() pos: 0 bytes read:32768 seeks:0 nb_streams:1
[png_pipe @ 000001b89b1017e0] After avformat_find_stream_info() pos: 41290 bytes read:41290 seeks:0 frames:1
[Parsed_movie_0 @ 000001b899616f20] seek_point:0 format_name:(null) file_name:img.png stream_index:-1
[graph 0 input from stream 0:0 @ 000001b89b151740] Setting 'video_size' to value '1280x720'
[graph 0 input from stream 0:0 @ 000001b89b151740] Setting 'pix_fmt' to value '0'
[graph 0 input from stream 0:0 @ 000001b89b151740] Setting 'time_base' to value '1/12800'
[graph 0 input from stream 0:0 @ 000001b89b151740] Setting 'pixel_aspect' to value '1/1'
[graph 0 input from stream 0:0 @ 000001b89b151740] Setting 'sws_param' to value 'flags=2'
[graph 0 input from stream 0:0 @ 000001b89b151740] Setting 'frame_rate' to value '25/1'
[graph 0 input from stream 0:0 @ 000001b89b151740] w:1280 h:720 pixfmt:yuv420p tb:1/12800 fr:25/1 sar:1/1 sws_param:flags=2
[format @ 000001b89b151340] compat: called with args=[yuv420p|yuvj420p|yuv422p|yuvj422p|yuv444p|yuvj444p|yuv420p10le|yuv422p10le|yuv444p10le|nv12|nv16|nv20le|nv21]
[format @ 000001b89b151340] Setting 'pix_fmts' to value 'yuv420p|yuvj420p|yuv422p|yuvj422p|yuv444p|yuvj444p|yuv420p10le|yuv422p10le|yuv444p10le|nv12|nv16|nv20le|nv21'
[auto_scaler_0 @ 000001b89b151f60] Setting 'flags' to value 'bicubic'
[auto_scaler_0 @ 000001b89b151f60] w:iw h:ih flags:'bicubic' interl:0
[Parsed_overlay_1 @ 000001b89b151680] auto-inserting filter 'auto_scaler_0' between the filter 'Parsed_movie_0' and the filter 'Parsed_overlay_1'
[AVFilterGraph @ 000001b89a00b6c0] query_formats: 5 queried, 3 merged, 1 already done, 0 delayed
[auto_scaler_0 @ 000001b89b151f60] w:1280 h:720 fmt:rgba sar:1/1 -> w:1280 h:720 fmt:yuva420p sar:1/1 flags:0x4
[Parsed_overlay_1 @ 000001b89b151680] main w:1280 h:720 fmt:yuv420p overlay w:1280 h:720 fmt:yuva420p
[Parsed_overlay_1 @ 000001b89b151680] [framesync @ 000001b8978dcf68] Selected 1/12800 time base
[Parsed_overlay_1 @ 000001b89b151680] [framesync @ 000001b8978dcf68] Sync level 2
[auto_scaler_0 @ 000001b89b151f60] w:1280 h:720 fmt:rgba sar:2835/2835 -> w:1280 h:720 fmt:yuva420p sar:1/1 flags:0x4
[Parsed_overlay_1 @ 000001b89b151680] n:1.000000 t:0.000000 pos:1015.000000 x:0.000000 xi:0 y:0.000000 yi:0
[libx264 @ 000001b899284360] using mv_range_thread = 24
[libx264 @ 000001b899284360] using SAR=1/1
[libx264 @ 000001b899284360] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 000001b899284360] profile High, level 3.1
[libx264 @ 000001b899284360] 264 - core 155 r2901 7d0ff22 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.83.100
    Stream #0:0(und), 0, 1/12800: Video: h264 (libx264), 1 reference frame (avc1 / 0x31637661), yuv420p(left), 1280x720 [SAR 1:1 DAR 16:9], 0/1, q=-1--1, 25 fps, 12800 tbn, 25 tbc (default)
    Metadata:
      creation_time   : 1970-01-01T00:00:00.000000Z
      handler_name    : VideoHandler
      encoder         : Lavc57.107.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1(und), 0, 1/48000: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, delay 1024, 341 kb/s (default)
    Metadata:
      creation_time   : 1970-01-01T00:00:00.000000Z
      handler_name    : SoundHandler
      encoder         : Lavc57.107.100 aac
Clipping frame in rate conversion by 0.000008
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    Last message repeated 1 times
[Parsed_movie_0 @ 000001b899616f20] EOF timestamp not reliable
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
[Parsed_overlay_1 @ 000001b89b151680] Copying data in avfilter.
[h264 @ 000001b8978de6c0] nal_unit_type: 1, nal_ref_idc: 2
[Parsed_overlay_1 @ 000001b89b151680] n:2.000000 t:0.040000 pos:108274.000000 x:0.000000 xi:0 y:0.000000 yi:0
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    Last message repeated 2 times
[Parsed_overlay_1 @ 000001b89b151680] Copying data in avfilter.
    Last message repeated 2 times
[h264 @ 000001b89780fa20] nal_unit_type: 1, nal_ref_idc: 2
[Parsed_overlay_1 @ 000001b89b151680] n:3.000000 t:0.080000 pos:111848.000000 x:0.000000 xi:0 y:0.000000 yi:0
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    Last message repeated 2 times
[Parsed_overlay_1 @ 000001b89b151680] Copying data in avfilter.
    Last message repeated 2 times
[h264 @ 000001b8978101c0] nal_unit_type: 1, nal_ref_idc: 2
[Parsed_overlay_1 @ 000001b89b151680] n:4.000000 t:0.120000 pos:115932.000000 x:0.000000 xi:0 y:0.000000 yi:0
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    Last message repeated 2 times

...
...
...

[Parsed_overlay_1 @ 000001b89b151680] n:4271.000000 t:170.800000 pos:31384220.000000 x:0.000000 xi:0 y:0.000000 yi:0
[libx264 @ 000001b899284360] frame=4214 QP=24.15 NAL=0 Slice:B Poc:120 I:0    P:411  SKIP:3189 size=496 bytes
[Parsed_overlay_1 @ 000001b89b151680] [framesync @ 000001b8978dcf68] Sync level 0
[out_0_0 @ 000001b89b151d00] EOF on sink link out_0_0:default.
[out_0_1 @ 000001b89942da00] EOF on sink link out_0_1:default.
No more output streams to write to, finishing.
[libx264 @ 000001b899284360] frame=4215 QP=23.77 NAL=0 Slice:B Poc:124 I:0    P:462  SKIP:3137 size=514 bytes
[libx264 @ 000001b899284360] frame=4216 QP=21.05 NAL=2 Slice:P Poc:134 I:134  P:1049 SKIP:2417 size=5719 bytes
...
...
frame= 4271 fps=112 q=-1.0 Lsize=   29425kB time=00:02:50.85 bitrate=1410.8kbits/s speed=4.46x    
video:22182kB audio:7125kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.400701%
Input file #0 (video.mp4):
  Input stream #0:0 (video): 4271 packets read (23193765 bytes); 4271 frames decoded; 
  Input stream #0:1 (audio): 8009 packets read (8199788 bytes); 8009 frames decoded (8201216 samples); 
  Total: 12280 packets (31393553 bytes) demuxed
Output file #0 (output.mp4):
  Output stream #0:0 (video): 4271 frames encoded; 4271 packets muxed (22714566 bytes); 
  Output stream #0:1 (audio): 8009 frames encoded (8201216 samples); 8010 packets muxed (7296351 bytes); 
  Total: 12281 packets (30010917 bytes) muxed
12280 frames successfully decoded, 0 decoding errors
[AVIOContext @ 000001b89982ee00] Statistics: 41290 bytes read, 0 seeks
[AVIOContext @ 000001b8978dd4e0] Statistics: 2 seeks, 118 writeouts
[libx264 @ 000001b899284360] frame I:44    Avg QP:15.98  size: 88754
[libx264 @ 000001b899284360] frame P:2394  Avg QP:21.02  size:  6501
[libx264 @ 000001b899284360] frame B:1833  Avg QP:25.25  size:  1770
[libx264 @ 000001b899284360] consecutive B-frames: 37.8% 11.5% 10.1% 40.6%
[libx264 @ 000001b899284360] mb I  I16..4: 18.1% 37.3% 44.6%
[libx264 @ 000001b899284360] mb P  I16..4:  1.4%  3.2%  0.4%  P16..4: 22.8%  5.4%  2.4%  0.0%  0.0%    skip:64.4%
[libx264 @ 000001b899284360] mb B  I16..4:  0.1%  0.5%  0.1%  B16..8: 17.8%  1.2%  0.2%  direct: 0.5%  skip:79.6%  L0:47.4% L1:50.0% BI: 2.6%
[libx264 @ 000001b899284360] 8x8 transform intra:57.5% inter:68.6%
[libx264 @ 000001b899284360] coded y,uvDC,uvAC intra: 54.0% 73.5% 28.9% inter: 5.3% 8.2% 0.4%
[libx264 @ 000001b899284360] i16 v,h,dc,p: 24% 31% 12% 32%
[libx264 @ 000001b899284360] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 24% 20% 20%  5%  6%  7%  6%  6%  6%
[libx264 @ 000001b899284360] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 26% 17% 11%  6%  8%  9%  7%  8%  6%
[libx264 @ 000001b899284360] i8c dc,h,v,p: 43% 25% 21% 11%
[libx264 @ 000001b899284360] Weighted P-Frames: Y:0.1% UV:0.1%
[libx264 @ 000001b899284360] ref P L0: 79.0%  9.6%  8.8%  2.6%  0.0%
[libx264 @ 000001b899284360] ref B L0: 92.7%  6.3%  0.9%
[libx264 @ 000001b899284360] ref B L1: 97.1%  2.9%
[libx264 @ 000001b899284360] kb/s:1063.63
[aac @ 000001b8977e6520] Qavg: 545.756
[AVIOContext @ 000001b8977eb6e0] Statistics: 31544589 bytes read, 2 seeks

I included full log replacing repetetive parts with ellipses

@tmm1
Copy link

tmm1 commented Jul 16, 2018

I agree that would make more sense. I can propose a patch for ffmpeg 4.1 to do it automatically.

(There may be some users who compile libavcodec statically and combine it with other archives into a single shared library, so perhaps exporting the global JNI_OnLoad could conflicts.)

Surprisingly this wasn't really discussed on the ffmpeg list when the api was implemented: https://ffmpeg.org/pipermail/ffmpeg-devel/2016-March/190546.html

cc @mbouron

@saudet
Copy link
Member

saudet commented Jul 16, 2018

Yeah, it wouldn't work too well for static builds...

@anonym24
Copy link

anonym24 commented Jul 16, 2018

@saudet

I use JavaCV FFmpeg with original OpenCV4Andoid
We still have to convert it to RGBA to be able to draw color text
If we use OpenCV putText on YuvFrame we can only draw black/white/gray

// init once
mRgba = new Mat();
mYuvFrameData= new Mat(mFrameHeight + (mFrameHeight/2), mFrameWidth, CvType.CV_8UC1);

// do next in onPreviewFrame(byte[] data, ...)
mYuvFrameData.put(0, 0, data);
Imgproc.cvtColor(mYuvFrameData, mRgba, Imgproc.COLOR_YUV2RGBA_NV21, 4);
// draw something on mRgba using putText method
if (mByte == null) mByte = new byte[(int)(mRgba.total()) * mRgba.channels()];
mRgba.get(0, 0, mByte);

Does JavaCV already supports FFmpegFrameRecorder with MediaCodec?

@saudet
Copy link
Member

saudet commented Jul 16, 2018

Yes, that's true OpenCV doesn't support YUV. But drawText does? Good to know.

According to @tmm1 yes it does.

@anonym24
Copy link

anonym24 commented Jul 16, 2018

FFmpeg Filter's drawText?
I think it can (I tried only white color, "drawtext=fontfile=" + fontPath + ":text='TEST': fontcolor=white: fontsize=96"), but I need dynamic text and it's much easier to change text with OpenCV before encoding each frame, so I decided not to use FFmpeg fitlers

@tmm1 will there be a little documentation how to use MediaCodec with FFmpegFrameRecorder?

@anonym24
Copy link

anonym24 commented Jul 16, 2018

seems OpenCV doesn't directly put text to data (put method makes copy)

mYuvFrameData.put(0, 0, data);
Imgproc.putText(mYuvFrameData, "test", mDatePosition, Core.FONT_HERSHEY_SIMPLEX,
                        0.8, mColorBlack, 5, Core.LINE_AA, false);

so when using such we still have to get new byte and use this byte and not old byte from onPreviewCallback

if (mByte == null) mByte = new byte[(int)(mYuvFrameData.total()) * mYuvFrameData.channels()];
mYuvFrameData.get(0, 0, mByte);

How does JavaCV OpenCVFrameConverter work? Does it create Mat from Frame and doesn't copy anything?
If so mb I will use it even if it allows only black/white text
Also can I do it with OpenCV4Android?

@saudet
Copy link
Member

saudet commented Jul 16, 2018

Yes, that's how it works. We can access the data pointer from the Java bindings of OpenCV as well: bytedeco/javacpp#38 (comment)

@anonym24
Copy link

anonym24 commented Jul 16, 2018

@saudet but actually copying/converting of frames (bytes, mats) isn't that big problem in video recording

because in next example (StackOverflow) with MediaRecorder I converted byte[] to Mat and then Mat to Btmap and then used that Bitmap to draw on MediaRecorder's Surface (lockCanvas)
and fps of video was pretty good (smooth enough, no lugs, even with 1080p)
but it doesn't work on all devices

https://stackoverflow.com/questions/51332386/mediarecorder-and-videosource-surface-stop-failed-1007-a-serious-android-bug

so it depends on how fast recorder can encode frames, I hope FFmpeg + MediaRecorder will work much better

@saudet
Copy link
Member

saudet commented Jul 18, 2018

I didn't test it, but something like this should work with JavaCV 1.4.2 now:

FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(...);
grabber.setVideoCodecName("h264_mediacodec");
...

@anonym24
Copy link

anonym24 commented Jul 18, 2018

Tried this

mFrameRecorder = new FFmpegFrameRecorder(mVideoFilePath, videoWidth, videoHeight, 1);
mFrameRecorder.setFormat("mp4");
mFrameRecorder.setVideoCodecName("h264_mediacodec");

_info

weird but it used "MPEG-4 part 2" codec

@saudet
Copy link
Member

saudet commented Jul 18, 2018

@anonym24 What does FFmpeg output to the log?

@anonym24
Copy link

anonym24 commented Jul 18, 2018

avutil.av_log_set_level(avutil.AV_LOG_VERBOSE);
FFmpegLogCallback.set();

Logs during start and stop FFmpegFrameRecorder

07-18 13:30:55.343 20877-20877/*** I/System.out: Output #0, mp4, to '/storage/A54E-14E9/Android/data/***/files/test.mp4':
07-18 13:30:55.344 20877-20877/*** I/System.out: Output #0, mp4, to '/storage/A54E-14E9/Android/data/***/files/test.mp4':
      Metadata:
      Metadata:
        encoder         : 
07-18 13:30:55.345 20877-20877/*** I/System.out:     encoder         : 
    Lavf58.12.100
    Lavf58.12.100
07-18 13:30:55.346 20877-20877/*** I/System.out:     Stream #0:0
        Stream #0:0
07-18 13:30:55.347 20877-20877/*** I/System.out: : Video: mpeg4, 1 reference frame (mp4v / 0x7634706D), yuv420p, 1280x720 (0x0), q=2-31, 400 kb/s
    : Video: mpeg4, 1 reference frame (mp4v / 0x7634706D), yuv420p, 1280x720 (0x0), q=2-31, 400 kb/s
    , 
    , 
    12288 tbn
07-18 13:30:55.348 20877-20877/*** I/System.out: 12288 tbn
07-18 13:30:55.659 20877-21159/*** V/RenderScript: 0x55cfffc700 Launching thread(s), CPUs 8

when I use mFrameRecorder.setVideoCodec(avcodec.AV_CODEC_ID_H264); there is much more logs than when using mFrameRecorder.setVideoCodecName("h264_mediacodec");

@saudet
Copy link
Member

saudet commented Jul 18, 2018

What does avcodec_find_decoder_by_name("h264_mediacodec")) return?

@anonym24
Copy link

anonym24 commented Jul 18, 2018

avcodec.AVCodec avCodec = avcodec.avcodec_find_decoder_by_name("h264_mediacodec");
if (avCodec != null) {
    Log.i(TAG, "avCodec != null, " + avCodec.name().getString() + " " + avCodec.long_name().getString());
} else {
    Log.i(TAG, "avCodec == null");
}

output

avCodec != null, h264_mediacodec H.264 Android MediaCodec decoder

@saudet
Copy link
Member

saudet commented Jul 18, 2018

Ok, looks good, what about avcodec_find_encoder_by_name("h264_mediacodec"))?

@anonym24
Copy link

anonym24 commented Jul 18, 2018

here's encoder:

avcodec.AVCodec avCodec = avcodec.avcodec_find_encoder_by_name("h264_mediacodec");
if (avCodec != null) {
    Log.i(TAG, "avCodec != null, " + avCodec.name().getString() + " " + avCodec.long_name().getString());
} else {
    Log.i(TAG, "avCodec == null");
}

it returns null

avCodec == null

@saudet
Copy link
Member

saudet commented Jul 18, 2018

Hum, looks like encoding isn't supported:
https://trac.ffmpeg.org/wiki/HWAccelIntro

@tmm1
Copy link

tmm1 commented Jul 18, 2018

Yes it looks like mediacodec encoders do not exist in ffmpeg. It wouldn't be very hard to add, but no one has submitted any patches so far.

@anonym24
Copy link

anonym24 commented Jul 18, 2018

@tmm1 can you do it? (if you're interested of course)
I don't really work with C or C++, it's not my subject

@saudet
Copy link
Member

saudet commented Oct 28, 2018

BTW, I've implemented support for multiple inputs in commit 3c92eef, so we can now use a filter graph like "[0][1]overlay", although I've decided to follow the [0:v] ... [v], etc as convention for the names of the inputs and outputs as it's really not clear how the ffmpeg program comes up with the names it uses: https://github.com/bytedeco/javacv/blob/master/platform/src/test/java/org/bytedeco/javacv/FrameFilterTest.java#L163

Please give it a try with the snapshots: http://bytedeco.org/builds/ Thanks!

@DeKinci
Copy link
Author

DeKinci commented Oct 30, 2018

It's great, now it is possible to create proper slow-mo filter and others with splitted audio and video editing without manually splitting streams. Thanks!

@davepaiva
Copy link

davepaiva commented Dec 20, 2019

I want to overlay two seperate PNG files on the live video stream at the same time. I have managed to overlay a single image on the video using the movie filter.
How do I add the second image at the same time?
Thanks

@DeKinci
Copy link
Author

DeKinci commented Dec 20, 2019

You can chain filters together, just direct first filter output to second's input.
[in]filter1[filtered];[filtered]filter2[out]
Also FYI there is the overlay filter and it works well for overlaying pngs on the live stream
https://ffmpeg.org/ffmpeg-filters.html#overlay-1

@davepaiva
Copy link

Thanks @DeKinci chaining filters together worked for me !

@saudet
Copy link
Member

saudet commented Mar 3, 2023

BTW, FFmpeg 6.0 now supports hardware accelerated encoding using MediaCodec, so we don't need to use its API directly anymore. Please give it a try with the snapshots: http://bytedeco.org/builds/

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

6 participants