0

I test the justin's code from How to cut video with FFmpeg C API, the sound is fine but have no image. The infomation of the output 5_1.mp4 is

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '5_1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.65.101
  Duration: 00:00:09.93, start: 0.000000, bitrate: 677 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720, 550 kb/s, 6.91 fps, 23.98 tbr, 90k tbn, 47.95 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]

I tried ffmpeg with command line ffmpeg -ss 00:00:00 -to 00:00:10 -i 5.mp4 -codec copy 5_0.mp4, it generates normal output and the infomation of the output is

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '5_0.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.65.101
  Duration: 00:00:10.14, start: 0.000000, bitrate: 815 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720, 685 kb/s, 23.98 fps, 23.98 tbr, 2500k tbn, 47.95 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]

I could not find where the problem is. How should I modify the code to deal with the black screen problem?

嬲你屋里娘
  • 303
  • 2
  • 7

1 Answers1

0

I change the code

if (dts_start_from[pkt.stream_index] == 0) {
    dts_start_from[pkt.stream_index] = pkt.dts;
    printf("dts_start_from: %s\n", av_ts2str(dts_start_from[pkt.stream_index]));
}
if (pts_start_from[pkt.stream_index] == 0) {
    pts_start_from[pkt.stream_index] = pkt.pts;
    printf("pts_start_from: %s\n", av_ts2str(pts_start_from[pkt.stream_index]));
}

to

if (dts_start_from[pkt.stream_index] <= 0) {
    dts_start_from[pkt.stream_index] = pkt.dts;
    printf("dts_start_from: %s\n", av_ts2str(dts_start_from[pkt.stream_index]));
}
if (pts_start_from[pkt.stream_index] <= 0) {
    pts_start_from[pkt.stream_index] = pkt.pts;
    printf("pts_start_from: %s\n", av_ts2str(pts_start_from[pkt.stream_index]));
}

and it seemed work properly

嬲你屋里娘
  • 303
  • 2
  • 7