[FFmpeg-user] Cutting on video frame

Louis Letourneau lletourn49 at gmail.com
Thu Jul 7 19:38:26 EEST 2016


Hello,
I pretty much have the same problem listed in this post in Sept 2015 which
got no answer for.
http://ffmpeg.org/pipermail/ffmpeg-user/2015-September/028281.html

When cutting a video, even when transcoding, I often have a small delay
between the video and audio.

When looking at the video with either vlc or ffplay, I see the first frame
shown twice.(The first is probably a dup until it the real pts is hit).

I was wondering if there is a way to force cutting on video frame
boundaries to avoid this.

Also when using -ss to cut exactly to the video frame closest to where I
want to cut. I still often get audio packets and frames with negative pts.

If It then convert this video from mp4 -> hls, the negative frames are now
positive and my video frame is push forward again.

Original video
ffprobe -show_frames -show_entries "frame=pkt_pts,media_type" 2708-1.mp4
[FRAME]
media_type=audio
pkt_pts=0
[/FRAME]
[FRAME]
media_type=audio
pkt_pts=1024
[/FRAME]
[FRAME]
media_type=audio
pkt_pts=2048
[/FRAME]
[FRAME]
media_type=audio
pkt_pts=3072
[/FRAME]
[FRAME]
media_type=audio
pkt_pts=4096
[/FRAME]
[FRAME]
media_type=audio
pkt_pts=5120
[/FRAME]
[FRAME]
media_type=audio
pkt_pts=6144
[/FRAME]
[FRAME]
media_type=audio
pkt_pts=7168
[/FRAME]
[FRAME]
media_type=audio
pkt_pts=8192
[/FRAME]
[FRAME]
media_type=video
pkt_pts=3780
[/FRAME]


Conveted video
ffmpeg -y -ss 0.042000 -i 2708-1.mp4 -vf
drawtext="fontfile=/usr/share/fonts/truetype/droid/DroidSans.ttf:text='%{n}
%{pts}':x=5:y=5:fontsize=24:fontcolor=yellow:box=1:boxcolor=red" -codec:a
libfdk_aac -b:a 128k -codec:v libx264 -crf 23 -preset fast -pix_fmt yuv420p
-flags +global_header -force_key_frames "expr:gte(t,n_forced*5)" -bf 0 a.mp4

Converted video (still has the problem)
ffprobe -show_frames -show_entries "frame=pkt_pts,media_type" a.mp4 | less
[FRAME]
media_type=audio
pkt_pts=-2048
[/FRAME]
[FRAME]
media_type=audio
pkt_pts=-1024
[/FRAME]
[FRAME]
media_type=audio
pkt_pts=0
[/FRAME]
[FRAME]
media_type=audio
pkt_pts=1024
[/FRAME]
[FRAME]
media_type=audio
pkt_pts=2048
[/FRAME]
[FRAME]
media_type=audio
pkt_pts=3072
[/FRAME]
[FRAME]
media_type=audio
pkt_pts=4096
[/FRAME]
[FRAME]
media_type=audio
pkt_pts=5120
[/FRAME]
[FRAME]
media_type=audio
pkt_pts=6144
[/FRAME]
[FRAME]
media_type=video
pkt_pts=0
[/FRAME]



And if I convert this one to hls
ffmpeg -y -i a.mp4 -codec copy -flags -global_header -hls_time 5
-hls_list_size 0 -hls_wrap 0 -hls_allow_cache 1 -hls_segment_filename
"tmp/2708-1_%04d.ts" -bsf:v h264_mp4toannexb tmp/2708-1.m3u8


I'm right back to the first video, all timestamps are positive and I have
the duplicate first frame.

I'm guessing there is a flag or an option to force frame boundaries or
remove negative audio packets but I can't find it.avoid_negative_ts just
offsets everything to the negative audio packets are the start of the video.

Thanks
Louis


More information about the ffmpeg-user mailing list