bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.53k stars 1.58k forks source link

Can't transocde h265 to h264 #2086

Closed zhoutian94 closed 1 year ago

zhoutian94 commented 1 year ago

I'm confused with this, the source video codec is H265, I want to transcode it to H264, So I set recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);, but the video codec of ouput stream still the H265, and can't to play 。 but when source is H264 is fine.

pom snippet:

     <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>javacv-platform</artifactId>
            <version>1.5.9</version>
        </dependency>

        <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>ffmpeg-platform-gpl</artifactId>
            <version>6.0-1.5.9</version>
        </dependency>

log snippet(input): (no error)


Info: Input #0, dhav, from 'java.io.BufferedInputStream@186e1b8e':

Info:   Duration: 
Info: N/A
Info: , start: 
Info: 1692716719.000000
Info: , bitrate: 
Info: N/A
Info: 

Info:   Stream #0:0
Debug: , 157, 1/1000
Info: : Audio: aac (LC), 32000 Hz, mono, fltp
Info: 

Info:   Stream #0:1
Debug: , 125, 1/1000
Info: : Video: hevc (Main), 1 reference frame, yuvj420p(pc, bt470bg/bt470bg/smpte170m, left), 1920x1080, 0/1
Info: , 
Info: 25 fps, 
Info: 25 tbr, 
Info: 1k tbn
Info: 

log snippet(ouput): (no error , and the log stuck in here)

Info: Output #0, flv, to 'rtmp://127.0.0.1:1935/myapp/m1':

Info:   Metadata:

Info:     encoder         : 
Info: Lavf60.3.100
Info: 

Info:   Stream #0:0
Debug: , 0, 1/1000
Info: : Video: hevc (Main), 1 reference frame ([12][0][0][0] / 0x000C), yuvj420p(pc, bt470bg/bt470bg/smpte170m, left), 1920x1080 (0x0), 0/1, q=2-31
Info: , 
Info: 25 fps, 
Info: 1k tbn
Info: 
saudet commented 1 year ago

We can easily accomplish this with the ffmpeg program: http://bytedeco.org/javacpp-presets/ffmpeg/apidocs/org/bytedeco/ffmpeg/ffmpeg.html

zhoutian94 commented 1 year ago

We can easily accomplish this with the ffmpeg program: http://bytedeco.org/javacpp-presets/ffmpeg/apidocs/org/bytedeco/ffmpeg/ffmpeg.html

thanks for you reply, for some reason I can only use "FFmpegFrameGrabber "and "FFmpegFrameRecorder", not ffmpeg directly , is that possible to solve these problem

zhoutian94 commented 1 year ago

I tried 'recorder.setVideoCodecName("libx264") ' and 'recorder.setVideoCodecName("H264") ', but no effect

saudet commented 1 year ago

thanks for you reply, for some reason I can only use "FFmpegFrameGrabber "and "FFmpegFrameRecorder", not ffmpeg directly , is that possible to solve these problem

Please try again with the snapshots: http://bytedeco.org/builds/

See issue https://github.com/bytedeco/javacv/issues/2039

zhoutian94 commented 1 year ago

thanks for you reply, for some reason I can only use "FFmpegFrameGrabber "and "FFmpegFrameRecorder", not ffmpeg directly , is that possible to solve these problem

Please try again with the snapshots: http://bytedeco.org/builds/

See issue #2039

Yes ,I tried again with javacv-platform 1.5.10-SNAPSHOT , and using denpendencies like these : (I'm not sure if the choosen module is right.)

try {
            Loader.load(org.bytedeco.ffmpeg.presets.avcodec.class);
            pushVideo(pushAddress, pushPotocol, grabber);
        } catch (UnsatisfiedLinkError e) {
            String path = Loader.cacheResource(avcodec.class, "windows-x86_64/avcodec-60.dll").getPath();
            new ProcessBuilder("D:\\dependencies\\DependenciesGui.exe", path).start().waitFor();
        }

But nothing error log show, the log still stuck in output.

Info: Output #0, flv, to 'rtmp://127.0.0.1:1935/myapp/m1':

Info:   Metadata:

Info:     encoder         : 
Info: Lavf60.3.100
Info: 

Info:   Stream #0:0
Debug: , 0, 1/1000
Info: : Video: hevc (Main), 1 reference frame ([12][0][0][0] / 0x000C), yuvj420p(pc, bt470bg/bt470bg/smpte170m, left), 1920x1080 (0x0), 0/1, q=2-31
Info: , 
Info: 25 fps, 
Info: 1k tbn
Info: 
zhoutian94 commented 1 year ago

I solved this problem, just replace 'recorder.recordPacket' with 'recorder.record'

lianyf1994 commented 10 months ago

Can javacv 1.5.3 solve the problem that h265 cannot be converted to h264?