bytedeco/javacv

Grabbing/recording packets doesn't work, EXCEPTION_ACCESS_VIOLATION.

Open

#818 opened on Oct 21, 2017

View on GitHub
 (38 comments) (0 reactions) (0 assignees)Java (1,583 forks)batch import
bughelp wanted

Repository metrics

Stars
 (6,985 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Hello, I'm trying to send a stream from grabber to recorder without transcoding. I already received some help from Samuel Audet, who pointed me to this sample: https://github.com/bytedeco/javacv/blob/master/samples/PacketRecorderTest.java#L53

I tried it, but it doesn't work, in two ways. First, the grabbed packets are obviously incorrect, judging by their size (1 byte), always-zero timestamp and non-changing state of the grabber. And after I put the first such packet to the recorder, the JVM fails with fatal error EXCEPTION_ACCESS_VIOLATION.

Here is the code:

public static void packetRecord(String inputFile, String outputFile) throws FrameGrabber.Exception, FrameRecorder.Exception {
      FFmpegFrameGrabber grabber=new FFmpegFrameGrabber(inputFile);
      grabber.start();
      FFmpegFrameRecorder recorder=new FFmpegFrameRecorder(
         outputFile, grabber.getImageWidth(), grabber.getImageHeight(),
         AUDIO_ENABLED? 1: 0
      );
      recorder.setSampleRate(grabber.getSampleRate());
      recorder.setFrameRate(grabber.getFrameRate());
      recorder.setVideoBitrate(grabber.getVideoBitrate());
      recorder.setVideoCodec(grabber.getVideoCodec());
      //recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
      
      recorder.start(grabber.getFormatContext());
      System.out.println("recorder started");
      avcodec.AVPacket packet;
      long t1=System.currentTimeMillis();
      while((packet=grabber.grabPacket())!=null){
         System.out.println("packet: "+packet);
         System.out.println("  ts: "+grabber.getTimestamp());
         recorder.recordPacket(packet);
         if((System.currentTimeMillis()-t1)>MAX_DURATION) break;
      }
      recorder.stop();
      grabber.stop();
   }

and the output:

recorder started
packet: org.bytedeco.javacpp.avcodec$AVPacket[address=0x153e5a20,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x153e5a20,deallocatorAddress=0x6a1c1c80]]
  ts: 0
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000007faab256356, pid=4852, tid=7620
#
# JRE version: Java(TM) SE Runtime Environment (8.0_40-b26) (build 1.8.0_40-b26)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.40-b25 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  [avformat-57.dll+0xc6356]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# D:\serge\my_projects\upwork\streaming\java\classes\hs_err_pid4852.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Input #0, avi, from '../../data/pepa10.avi':
  Metadata:
    encoder         : Lavf57.82.101
  Duration: 00:00:10.01, start: 0.000000, bitrate: 628 kb/s
    Stream #0:0: Video: mpeg4 (Simple Profile) (xvid / 0x64697678), yuv420p, 720x576 [SAR 248:231 DAR 310:231], 450 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc
    Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, s16p, 160 kb/s
[avi @ 0000000015d400a0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
[avi @ 0000000015d400a0] Aspect ratio mismatch between muxer (1/1) and encoder layer (248/231)
Output #0, avi, to '../../data/pepa10copy.avi':
    Stream #0:0: Video: mpeg4 (Simple Profile) (xvid / 0x64697678), yuv420p, 720x576 [SAR 248:231 DAR 310:231], q=2-31, 450 kb/s, SAR 1:1 DAR 5:4, 25 tbn, 25 tbc
    Stream #0:1: Unknown: none
[avi @ 0000000015d400a0] Timestamps are unset in a packet for stream 1. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[avi @ 0000000015d400a0] Encoder did not produce proper pts, making some up.

Process completed.

Did anyone have success with packet transmission?

Thanks a lot

Contributor guide