[FFmpeg-user] Problem with split and concat mp4.

César Sepúlveda csepulveda at mediastre.am
Mon Sep 8 14:44:17 CEST 2014


Hello everyone.

I write because i have a problem with cut mp4 and ffmpeg.

I need make precise cuts without re-encode the original video.

FFmpeg makes cuts without trouble but as long as the cut is started on a
keyframe.

To solve this we are doing the next one.

We analyzed the video with ffprobe reading the frames which are keyframes
in a limited time using read_intervals and cut from the nearest keyframe
top.

We perform the transcoding from the second desired to the frame before
cutting keyframe and left it in .TS format (use the same encoding options
for this piece of video, that we get with ffprobe)

Then join the two segments with concat filter into only one mp4 file.

The operation is super fast, even for large videos, the problem is that the
video does not play well in certain devices or video players, the most
common failure is when the video is transformed to HLS format.

Am I missing something? can you give me some help?

Thank you very much!.

PS: sorry mi english.

Example:
###analysis keyframes and codec options
ffprobe -read_intervals 00:11:31%00:11:34 -select_streams v:0 -show_frames
-show_streams -print_format json -i
/mnt/gfs1/medias/public/v/509bccb2e213843e650009eb/53e4d93747372bcc5a7b4e92_53e4d93747372bcc5a7b4e94.mp4

#### cut from fisrt keyframe found.
ffmpeg -y -ss 692.025000 -i
/mnt/gfs1/medias/public/v/509bccb2e213843e650009eb/53e4d93747372bcc5a7b4e92_53e4d93747372bcc5a7b4e94.mp4
-t 2101.571062 -c copy -f mp4
/mnt/gfs1/medias/public/v/509bccb2e213843e650009eb/53e4d93747372bcc5a7b4e92_53e4d93747372bcc5a7b4e94.mp4.MDA6MTE6MzEtMDA6MzU6MDE=_1.mp4

#### encoding from second 691.991685 using options prefile, level and bf
from original video
ffmpeg -y -ss 691.991685 -i
/mnt/gfs1/medias/public/v/509bccb2e213843e650009eb/53e4d93747372bcc5a7b4e92_53e4d93747372bcc5a7b4e94.mp4
-t 0.03331500000001597 -acodec libfaac -vcodec libx264 -profile:v baseline
-level 31 -bf 0
/mnt/gfs1/medias/public/v/509bccb2e213843e650009eb/53e4d93747372bcc5a7b4e92_53e4d93747372bcc5a7b4e94.mp4.MDA6MTE6MzEtMDA6MzU6MDE=_2.mp4

###transform parts to ts
ffmpeg -y -i
/mnt/gfs1/medias/public/v/509bccb2e213843e650009eb/53e4d93747372bcc5a7b4e92_53e4d93747372bcc5a7b4e94.mp4.MDA6MTE6MzEtMDA6MzU6MDE=_1.mp4
-c copy -vbsf h264_mp4toannexb
/mnt/gfs1/medias/public/v/509bccb2e213843e650009eb/53e4d93747372bcc5a7b4e92_53e4d93747372bcc5a7b4e94.mp4.MDA6MTE6MzEtMDA6MzU6MDE=_1.ts
ffmpeg -y -i
/mnt/gfs1/medias/public/v/509bccb2e213843e650009eb/53e4d93747372bcc5a7b4e92_53e4d93747372bcc5a7b4e94.mp4.MDA6MTE6MzEtMDA6MzU6MDE=_2.mp4
-c copy -vbsf h264_mp4toannexb
/mnt/gfs1/medias/public/v/509bccb2e213843e650009eb/53e4d93747372bcc5a7b4e92_53e4d93747372bcc5a7b4e94.mp4.MDA6MTE6MzEtMDA6MzU6MDE=_2.ts

###concat video
ffmpeg -y -i
concat:"/mnt/gfs1/medias/public/v/509bccb2e213843e650009eb/53e4d93747372bcc5a7b4e92_53e4d93747372bcc5a7b4e94.mp4.MDA6MTE6MzEtMDA6MzU6MDE=_2.ts|/mnt/gfs1/medias/public/v/509bccb2e213843e650009eb/53e4d93747372bcc5a7b4e92_53e4d93747372bcc5a7b4e94.mp4.MDA6MTE6MzEtMDA6MzU6MDE=_1.ts"
-c copy -bsf:a aac_adtstoasc -f mp4
/mnt/gfs1/medias/public/v/509bccb2e213843e650009eb/540d9b4dbd3025a36dc27689.mp4


###Problem making hls with fffmpeg:
root at web2:~# ffmpeg -i
/mnt/gfs1/medias/public/v/509bccb2e213843e650009eb/540d9b4dbd3025a36dc27689.mp4
-acodec copy -bsf:v h264_mp4toannexb -vcodec copy -f hls /tmp/playlist.m3u8
ffmpeg version git-2014-09-03-75a9859 Copyright (c) 2000-2014 the FFmpeg
developers
  built on Sep  3 2014 22:42:41 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --prefix=/opt/ffmpeg --extra-cflags=-I/opt/ffmpeg/include
--extra-ldflags=-L/opt/ffmpeg/lib --extra-libs=-ldl --enable-gpl
--enable-libfaac --enable-libx264 --enable-nonfree
  libavutil      54.  7.100 / 54.  7.100
  libavcodec     56.  1.100 / 56.  1.100
  libavformat    56.  4.100 / 56.  4.100
  libavdevice    56.  0.100 / 56.  0.100
  libavfilter     5.  0.103 /  5.  0.103
  libswscale      3.  0.100 /  3.  0.100
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  0.100 / 53.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from
'/mnt/gfs1/medias/public/v/509bccb2e213843e650009eb/540d9b4dbd3025a36dc27689.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.4.100
  Duration: 00:35:01.64, start: 0.000000, bitrate: 1305 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 /
0x31637661), yuv420p, 854x480 [SAR 1:1 DAR 427:240], 1202 kb/s, 30 fps,
29.97 tbr, 90k tbn, 59.94 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, mono, fltp,
93 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
[mpegts @ 0x23a00c0] Using AVStream.codec.time_base as a timebase hint to
the muxer is deprecated. Set AVStream.time_base instead.
    Last message repeated 1 times
[adts @ 0x23a1000] Using AVStream.codec.time_base as a timebase hint to the
muxer is deprecated. Set AVStream.time_base instead.
Output #0, hls, to '/tmp/playlist.m3u8':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.4.100
    Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p, 854x480
[SAR 1:1 DAR 427:240], q=2-31, 1202 kb/s, 30 fps, 29.97 tbn, 29.97 tbc
(default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, mono, 93
kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[hls @ 0x23bfcc0] Non-monotonous DTS in output stream 0:0; previous: 0,
current: 0; changing to 1. This may result in incorrect timestamps in the
output file.
[hls @ 0x23bfcc0] Non-monotonous DTS in output stream 0:0; previous: 1,
current: 1; changing to 2. This may result in incorrect timestamps in the
output file.
[hls @ 0x23bfcc0] Non-monotonous DTS in output stream 0:0; previous: 2,
current: 2; changing to 3. This may result in incorrect timestamps in the
output file.
[hls @ 0x23bfcc0] Non-monotonous DTS in output stream 0:0; previous: 3,
current: 3; changing to 4. This may result in incorrect timestamps in the
output file.
.....
.....
.....
[hls @ 0x23bfcc0] Non-monotonous DTS in output stream 0:0; previous: 63046,
current: 62983; changing to 63047. This may result in incorrect timestamps
in the output file.
[hls @ 0x23bfcc0] Non-monotonous DTS in output stream 0:0; previous: 63047,
current: 62984; changing to 63048. This may result in incorrect timestamps
in the output file.
[hls @ 0x23bfcc0] Non-monotonous DTS in output stream 0:0; previous: 63048,
current: 62985; changing to 63049. This may result in incorrect timestamps
in the output file.
frame=63050 fps=2419 q=-1.0 Lsize=N/A time=00:35:03.76 bitrate=N/A
video:308430kB audio:24070kB subtitle:0kB other streams:0kB global
headers:0kB muxing overhead: unknown


Url HLS video:
Player: http://www.jwplayer.com/wizard/
Url:
http://edge-20-us.edge.mdstrm.com/media-us/_definst_/v/509bccb2e213843e650009eb/540d9b4dbd3025a36dc27689.mp4/playlist.m3u8


--
César Sepúlveda.


More information about the ffmpeg-user mailing list