[FFmpeg-devel] [PATCH] fix stream copy

Maksym Veremeyenko verem
Wed Jan 13 16:09:08 CET 2010


Hi,

During cutting some MOV files i found strange behavior with number of 
frames copied to new file. The problems come from wrong codec->timebase 
value that is guessed from stream->time_base. For MOV stream->time_base 
is setted from time_scale that could be 25, 60, 6000, 2997 values - as 
result stream->time_base will have a values 1/25, 1/600, 1/2997 (i have 
such sample). That cause codec->timebase been set to that values later:

[root at diva-proxy 3]# /home/enctools/bin/ffmpeg -i HL_001_036_DV_FX.mov
FFmpeg version SVN-r21010, Copyright (c) 2000-2010 Fabrice Bellard, et al.
   built on Jan  4 2010 11:21:04 with gcc 4.3.2 20081105 (Red Hat 4.3.2-7)
   configuration: --prefix=/home/enctools --enable-libfaac 
--enable-libfaad --enable-libmp3lame --enable-postproc --enable-pthreads 
--enable-libx264 --enable-libxvid 
--extra-cflags=-I/home/enctools/include 
--extra-ldflags=-L/home/enctools/lib --enable-shared --enable-gpl 
--enable-nonfree --enable-avfilter --enable-avfilter-lavf
   libavutil     50. 7. 0 / 50. 7. 0
   libavcodec    52.45. 0 / 52.45. 0
   libavformat   52.46. 0 / 52.46. 0
   libavdevice   52. 2. 0 / 52. 2. 0
   libavfilter    1.13. 0 /  1.13. 0
   libswscale     0. 7. 2 /  0. 7. 2
   libpostproc   51. 2. 0 / 51. 2. 0
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x8192390]MAX_READ_SIZE:5000000 reached

Seems stream 0 codec frame rate differs from container frame rate: 
2997.00 (2997/1) -> 29.97 (30000/1001)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'HL_001_036_DV_FX.mov':
   Duration: 00:00:04.17, start: 0.000000, bitrate: 82337 kb/s
     Stream #0.0(eng): Video: png, rgb24, 720x480, 80919 kb/s, PAR 
648:720 DAR 27:20, 29.97 fps, 29.97 tbr, 2997 tbn, 2997 tbc
     Stream #0.1(eng): Audio: pcm_s16be, 44100 Hz, 2 channels, s16, 1411 
kb/s
At least one output file must be specified

resulting is 2997 tbn, 2997 tbc

Patch *mov.c-try_set_codec_time_base.patch* try to setup codec->time_base

Next patch *ffmpeg.c-do_not_override_codec_time_base.patch* fix output 
codec time_base overriding in ffmpeg.c that cause assigning
[...]
                 codec->time_base = ist->st->time_base;
[...]
that assigned to wrong value and as result one second cut outputs 600 
frames if source mov file has time_scale value 600:


[root at diva-proxy 3]# /home/enctools/bin/ffmpeg -i snoop_dog_105_d.mov -t 
1.0 -vcodec copy -an test2.mov
FFmpeg version SVN-r21010, Copyright (c) 2000-2010 Fabrice Bellard, et al.
   built on Jan  4 2010 11:21:04 with gcc 4.3.2 20081105 (Red Hat 4.3.2-7)
   configuration: --prefix=/home/enctools --enable-libfaac 
--enable-libfaad --enable-libmp3lame --enable-postproc --enable-pthreads 
--enable-libx264 --enable-libxvid 
--extra-cflags=-I/home/enctools/include 
--extra-ldflags=-L/home/enctools/lib --enable-shared --enable-gpl 
--enable-nonfree --enable-avfilter --enable-avfilter-lavf
   libavutil     50. 7. 0 / 50. 7. 0
   libavcodec    52.45. 0 / 52.45. 0
   libavformat   52.46. 0 / 52.46. 0
   libavdevice   52. 2. 0 / 52. 2. 0
   libavfilter    1.13. 0 /  1.13. 0
   libswscale     0. 7. 2 /  0. 7. 2
   libpostproc   51. 2. 0 / 51. 2. 0
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'snoop_dog_105_d.mov':
   Duration: 00:03:02.28, start: 0.000000, bitrate: 30336 kb/s
     Stream #0.0(eng): Video: dvvideo, yuv420p, 720x576, 28800 kb/s, 25 
fps, 25 tbr, 600 tbn, 25 tbc
     Stream #0.1(eng): Audio: pcm_s16be, 48000 Hz, 2 channels, s16, 1536 
kb/s
Output #0, mov, to 'test2.mov':
     Stream #0.0(eng): Video: dvvideo, yuv420p, 720x576, q=2-31, 28800 
kb/s, 600 tbn, 600 tbc
Stream mapping:
   Stream #0.0 -> #0.0
Press [q] to stop encoding
frame=  600 fps=  0 q=-1.0 Lsize=   84378kB time=23.96 
bitrate=28847.1kbits/s
video:84375kB audio:0kB global headers:0kB muxing overhead 0.003558%

After applying patches i am able to cut desired number of seconds..

Please comment.

-- 
________________________________________
Maksym Veremeyenko

-------------- next part --------------
A non-text attachment was scrubbed...
Name: mov.c-try_set_codec_time_base.patch
Type: text/x-patch
Size: 592 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100113/398be6ee/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ffmpeg.c-do_not_override_codec_time_base.patch
Type: text/x-patch
Size: 891 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100113/398be6ee/attachment-0001.bin>



More information about the ffmpeg-devel mailing list