Discussion:
[FFmpeg-user] Frame/gop accurate video splitting (fps, gop, length known)
Artur Bodera
2009-12-28 11:48:53 UTC
Permalink
Hey there!

A simple use case:
1) a sample mp4 file of 23.98 tbr, 264 + aac, 1:51.27 in length
2) the file (lotr trailer) encoded with: ./ffmpeg -i
./lordoftherings_h640_ml.mov -vcodec libx264 -g 50 ./lord.mp4
3) we want to split it in 3 parts: 30s, 10s and the rest of the stream

Chunks we want to have:
1) ~30s (00:00:00 - 00:00:30)
2) ~10s (00:00:30 - 00:00:40)
3) ~71s (00:00:40 - 00:01:51)

File info:
Duration: 00:01:51.27, start: 0.000000, bitrate: 256 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 640x272, 192 kb/s, 47.90 fps,
23.98 tbr, 24k tbn, 47.95 tbc
Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 58 kb/s


The only tools right now are -vframes, -ss and -t.
Frame-accurate seeking is missing/broken (?). Below is my approach.
a) chunk 1 is 30s, so with 23.98 fps that gives 719.5 frames.
b) Because it's gop 50 we round down to 700 frames = 29.1909925 seconds from
start
c) Chunk 1 extraction: "-vframes 699"
d) Chunk 2 starts from frames 700 and ends in 10s = 239.8 frames ~ 250
frames (gop 50)
e) Chunk 2 extraction: "-ss 29.1909925 -vframes 250"
f) Chunk 3 starts at 40s = 959.2th frames (23.98 fps). Rounding down to 50
gives us 950th frame
g) 950th frame is at aproximately 39.61635 sec.
g) Chunk 3 extraction: "-ss 39.61635"


Of course I wouldn't be bothering the community if it worked properly :-)
The chunks are off by many seconds, lengths are off.
Please assist - what am I doing wrong? Is there any more elegant way to do
that?

Also: a simpler case that I thought would "just work" - split the stream in
two:
./ffmpeg -y -ss -t 30 -i ./lord.mp4 -vcodec copy -acodec copy
lord-chunk1.mp4
./ffmpeg -y -ss 00:00:30 -i ./lord.mp4 -vcodec copy -acodec copy
lord-chunk2.mp4

It doesn't work! This will also end badly with two arbitrary length chunks
with seek times that make little sense.


How is it done properly?

Thanks!


Arthur.

ps: FFmpeg version SVN-r20880
--
__
/.)\ +48 695 600 936
\(./ abodera at gmail.com
Artur Bodera
2009-12-30 12:29:06 UTC
Permalink
Post by Artur Bodera
Hey there!
It doesn't work! This will also end badly with two arbitrary length chunks
with seek times that make little sense.
How is it done properly?
Bump :-)

None splits videos ?

Any suggestions are welcomed!

A.
--
__
/.)\ +48 695 600 936
\(./ abodera at gmail.com
Artur Bodera
2010-01-04 09:51:34 UTC
Permalink
Post by Artur Bodera
Hey there!
It doesn't work! This will also end badly with two arbitrary length chunks
with seek times that make little sense.
How is it done properly?
How to just split a video into 3 parts?
--
__
/.)\ +48 695 600 936
\(./ abodera at gmail.com
Artur Bodera
2010-01-06 10:51:40 UTC
Permalink
[...]
? 1)? ~30s (00:00:00 - 00:00:30)
? 2)? ~10s (00:00:30 - 00:00:40)
? 3)? ~71s (00:00:40 - 00:01:51)
? Duration: 00:01:51.27, start: 0.000000, bitrate: 256 kb/s
??? Stream #0.0(eng): Video: h264, yuv420p, 640x272, 192 kb/s, 47.90 fps,
23.98 tbr, 24k tbn, 47.95 tbc
??? Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 58 kb/s
A small test - the easy way just using -ss and -t:

Encoding of chunk 1:
ffmpeg -y -t 30 -i lord.mp4 -vcodec copy -acodec copy lord-c1.mp4
result:
Duration: 00:00:30.05, start: 0.000000, bitrate: 286 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 640x272, 237 kb/s, 47.95
fps, 23.98 tbr, 48k tbn, 47.95 tbc
Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 43 kb/s

Encoding of chunk 2:
ffmpeg -y -ss 30 -t 10 -i lord.mp4 -vcodec copy -acodec copy lord-c2.mp4
result:
Duration: 00:00:15.27, start: 0.000000, bitrate: 226 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 640x272, 156 kb/s, 47.95
fps, 23.98 tbr, 48k tbn, 47.95 tbc
Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 64 kb/s

Encoding of chunk 3:
ffmpeg -y -ss 40 -i lord.mp4 -vcodec copy -acodec copy lord-c3.mp4
result:
Duration: 00:01:12.12, start: 0.000000, bitrate: 268 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 640x272, 199 kb/s, 47.95
fps, 23.98 tbr, 48k tbn, 47.95 tbc
Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 63 kb/s


After re-joining the video has 117.44 s (the original file had 111,27s).
The fragments are inaccurate and overlap.
--
__
/.)\ +48 695 600 936
\(./ abodera at gmail.com
Phil Rhodes
2010-01-06 11:35:05 UTC
Permalink
Post by Artur Bodera
Duration: 00:00:30.05
Hasn't anyone working on ffmpeg ever heard of timecode? You know, hours,
minutes, seconds and frames, as is the standard for timing video in more or
less all cases except ffmpeg?

Ah, yes, they have:

https://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2007-April/027586.html

...but they thought they knew better.

Facepalm.

P
Jan Stary
2010-01-06 11:47:19 UTC
Permalink
Post by Phil Rhodes
Post by Artur Bodera
Duration: 00:00:30.05
Hasn't anyone working on ffmpeg ever heard of timecode? You know, hours,
minutes, seconds and frames, as is the standard for timing video in more
or less all cases except ffmpeg?
Don't know about timecode, but actually with 47.90 fps,
a "chunk of length 00:00:10.0" doesn't even necessary
correspond to one definite border frame. Right?
Jan Stary
2010-01-06 12:34:35 UTC
Permalink
Post by Jan Stary
Post by Phil Rhodes
Post by Artur Bodera
Duration: 00:00:30.05
Hasn't anyone working on ffmpeg ever heard of timecode? You know, hours,
minutes, seconds and frames, as is the standard for timing video in more
or less all cases except ffmpeg?
Don't know about timecode, but actually with 47.90 fps,
a "chunk of length 00:00:10.0" doesn't even necessary
correspond to one definite border frame. Right?
No really, with 47.90 fps and -g 50, how many vframes
is the "first 10 seconds" supposed to have?
Artur Bodera
2010-01-06 13:38:14 UTC
Permalink
Post by Jan Stary
No really, with 47.90 fps and -g 50, how many vframes
is the "first 10 seconds" supposed to have?
Let's simplify the whole thing.
Folks, please suggest how can I split the file in two?

My attempt:
Original file: Duration: 00:01:51.27, start: 0.000000, bitrate: 268 kb/s
Command: ffmpeg -t 55 -i lord.mp4 -vcodec copy -acodec copy lord-half1.mp4
Command: ffmpeg -ss 55 -i lord.mp4 -vcodec copy -acodec copy lord-half2.mp4
Result:
half1: Duration: 00:00:55.03, start: 0.000000, bitrate: 320 kb/s
half2: Duration: 00:00:56.32, start: 0.000000, bitrate: 219 kb/s

Length mismatch. In the original file, there is a white blast between
the scene with the Black Riders and Gandalf's face. It's missing in
the end of half1 and beginning of half2.

I've rejoined the files to verify:
# ffmpeg -i lord-half1.mp4 -vcodec mpeg2video -acodec copy lord-half1.mpg
# ffmpeg -i lord-half2.mp4 -vcodec mpeg2video -acodec copy lord-half2.mpg
# cat lord-half1.mpg lord-half2.mpg > lord-joined.mpg
The missing scene is more visible now.


Normalization attempt:
1. 55'th second is 2637,25 frames (47.95 fps).
2. Rounding down to 2600 frames (gop 50)
3. 2600 frames is close to 54.223149113660062565172054223149 seconds
4. Rounding up to 54.2232 and crossing fingers
5. ffmpeg -t 54.2232 -i lord.mp4 gives us: Duration: 00:00:54.24
6. ffmpeg -ss 54.2232 -i lord.mp4 gives us file: Duration: 00:00:59.20
7. total length: 113.44 original length 111,27


a workaround attempt:
6. The -t 54.2232 gave us duration 54.24 so we will seek directly to it
7. ffmpeg -ss 54.24 -i lord.mp4 gives us file: Duration: 00:00:59.20
7. total length: 113.44 Looks clear!

Unfortunatelly the scene where Saruman throws Gandalf in the air is
visible twice.
--
__
/.)\ +48 695 600 936
\(./ abodera at gmail.com
belcampo
2010-01-06 14:18:39 UTC
Permalink
Post by Artur Bodera
Post by Jan Stary
No really, with 47.90 fps and -g 50, how many vframes
is the "first 10 seconds" supposed to have?
Let's simplify the whole thing.
Folks, please suggest how can I split the file in two?
Original file: Duration: 00:01:51.27, start: 0.000000, bitrate: 268 kb/s
Command: ffmpeg -t 55 -i lord.mp4 -vcodec copy -acodec copy lord-half1.mp4
Command: ffmpeg -ss 55 -i lord.mp4 -vcodec copy -acodec copy lord-half2.mp4
half1: Duration: 00:00:55.03, start: 0.000000, bitrate: 320 kb/s
half2: Duration: 00:00:56.32, start: 0.000000, bitrate: 219 kb/s
Length mismatch. In the original file, there is a white blast between
the scene with the Black Riders and Gandalf's face. It's missing in
the end of half1 and beginning of half2.
# ffmpeg -i lord-half1.mp4 -vcodec mpeg2video -acodec copy lord-half1.mpg
# ffmpeg -i lord-half2.mp4 -vcodec mpeg2video -acodec copy lord-half2.mpg
# cat lord-half1.mpg lord-half2.mpg > lord-joined.mpg
The missing scene is more visible now.
1. 55'th second is 2637,25 frames (47.95 fps).
2. Rounding down to 2600 frames (gop 50)
3. 2600 frames is close to 54.223149113660062565172054223149 seconds
4. Rounding up to 54.2232 and crossing fingers
5. ffmpeg -t 54.2232 -i lord.mp4 gives us: Duration: 00:00:54.24
6. ffmpeg -ss 54.2232 -i lord.mp4 gives us file: Duration: 00:00:59.20
7. total length: 113.44 original length 111,27
6. The -t 54.2232 gave us duration 54.24 so we will seek directly to it
7. ffmpeg -ss 54.24 -i lord.mp4 gives us file: Duration: 00:00:59.20
7. total length: 113.44 Looks clear!
Unfortunatelly the scene where Saruman throws Gandalf in the air is
visible twice.
IMHO you need to work on video and audio separatedly. Video and audio
almost always have a delay to each other.
Say audio lags .08 which in your case is about 4 frames.
If you say I want 54secs of a movie you'll get 54.08
If you specify -v 2600 you'll get that amount of frames and audio will
be a little short.
I use this method to transcode first all video from 1source with
3DualCorePC's and then transcode audio part separated and then mux them
together to 1encoded file.
To make it work you have to know the GOP-size and split at that point
and that point only. The -v amount has to be 1less in my experience with
PAL DVB sources. It may/could be different on other source material.
Hope it helps.
Jan Stary
2010-01-06 14:27:45 UTC
Permalink
Post by Artur Bodera
Post by Jan Stary
No really, with 47.90 fps and -g 50, how many vframes
is the "first 10 seconds" supposed to have?
Let's simplify the whole thing.
Folks, please suggest how can I split the file in two?
Original file: Duration: 00:01:51.27, start: 0.000000, bitrate: 268 kb/s
Also,

$ ffmpeg -i lord.mp4
FFmpeg version SVN-r21032, Copyright (c) 2000-2010 Fabrice Bellard, et al.
built on Jan 6 2010 13:45:52 with gcc 3.3.5 (propolice)
configuration:
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
libswscale 0. 7. 2 / 0. 7. 2
Compiler did not align stack variables. Libavcodec has
been miscompiled and may be very slow or crash. This is not a bug in
libavcodec, but in the compiler. You may try recompiling using gcc >=
4.2. Do not report crashes to FFmpeg developers.
Seems stream 0 codec frame rate differs from container frame rate:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
47.95 (48000/ 1001) -> 23.98 (24000/1001)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'lord.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf52.43.0
Duration: 00:01:51.27, start: 0.000000, bitrate: 268 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 640x272, 204 kb/s, 47.90 fps, 23.98 tbr, 24k tbn, 47.95 tbc
Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 58 kb/s
At least one output file must be specified

This is something you created from "original file",
in a way that results in a broken container header.
Can you, pretty please, give us the original mov file?
Post by Artur Bodera
Command: ffmpeg -t 55 -i lord.mp4 -vcodec copy -acodec copy lord-half1.mp4
Command: ffmpeg -ss 55 -i lord.mp4 -vcodec copy -acodec copy lord-half2.mp4
half1: Duration: 00:00:55.03, start: 0.000000, bitrate: 320 kb/s
half2: Duration: 00:00:56.32, start: 0.000000, bitrate: 219 kb/s
Length mismatch. In the original file, there is a white blast between
the scene with the Black Riders and Gandalf's face. It's missing in
the end of half1 and beginning of half2.
# ffmpeg -i lord-half1.mp4 -vcodec mpeg2video -acodec copy lord-half1.mpg
# ffmpeg -i lord-half2.mp4 -vcodec mpeg2video -acodec copy lord-half2.mpg
# cat lord-half1.mpg lord-half2.mpg > lord-joined.mpg
The missing scene is more visible now.
1. 55'th second is 2637,25 frames (47.95 fps).
ffmpeg says the video stream is 47.90 fps, not 47.95 fps.
Post by Artur Bodera
2. Rounding down to 2600 frames (gop 50)
3. 2600 frames is close to 54.223149113660062565172054223149 seconds
4. Rounding up to 54.2232 and crossing fingers
5. ffmpeg -t 54.2232 -i lord.mp4 gives us: Duration: 00:00:54.24
6. ffmpeg -ss 54.2232 -i lord.mp4 gives us file: Duration: 00:00:59.20
7. total length: 113.44 original length 111,27
6. The -t 54.2232 gave us duration 54.24 so we will seek directly to it
7. ffmpeg -ss 54.24 -i lord.mp4 gives us file: Duration: 00:00:59.20
7. total length: 113.44 Looks clear!
Unfortunatelly the scene where Saruman throws Gandalf in the air is
visible twice.
--
__
/.)\ +48 695 600 936
\(./ abodera at gmail.com
_______________________________________________
ffmpeg-user mailing list
ffmpeg-user at mplayerhq.hu
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Artur Bodera
2010-01-06 21:00:03 UTC
Permalink
Post by Jan Stary
This is something you created from "original file",
in a way that results in a broken container header.
Can you, pretty please, give us the original mov file?
http://www.ementor.pl/ffmpeg-split/lordoftherings_h640_ml.mov
Post by Jan Stary
Post by Artur Bodera
1. 55'th second is 2637,25 frames (47.95 fps).
ffmpeg says the video stream is 47.90 fps, not 47.95 fps.
Recalculated, recoded...

1. 55'th second is 2634,5 frames (47.90 fps).
2. Rounding down to 2600 frames (gop 50)
3. 2600 frames is close to 54.279749478079331941544885177453 seconds
4. Rounding DOWN to 54.2797
5. ffmpeg -t 54.2797 -i lord.mp4 gives us: Duration: 00:00:54.32
6. ffmpeg -ss 54.2797 -i lord.mp4 gives us file: Duration: 00:00:59.20
7. total length: 113.52 original length 111,27

The halves overlap .... so no luck there.
--
__
/.)\ +48 695 600 936
\(./ abodera at gmail.com
Phil Rhodes
2010-01-06 15:15:23 UTC
Permalink
Post by Jan Stary
Don't know about timecode, but actually with 47.90 fps,
a "chunk of length 00:00:10.0" doesn't even necessary
correspond to one definite border frame. Right?
That's the whole point of timecode; it lets you simply number the frames so
you can specify edit points, without worrying about how this relates to real
time. Schemes like drop-frame timecode are designed to approximately correct
these disparities (though obviously Michael Niedermeyer knows better than
the entire film and TV industry, good thing we have him on board).

That said none of this will help you with such an oddball frame rate.
Where'd you get this file - is it double-rate 23.976 for some reason? There
hasn't traditionally been drop-frame rates for 23.976. I'm not sure why this
is, but I'd guess it's because feature films don't generally have to worry
about a minute or so's duration either way. There are certainly drop-frame
schemes for the other "doubled" rates that are becoming more prevalent,
particularly in 720p HD.

Anyway, this is all an aside to the original question.

P
Artur Bodera
2010-01-06 21:41:04 UTC
Permalink
Post by Phil Rhodes
That said none of this will help you with such an oddball frame rate.
Where'd you get this file - is it double-rate 23.976 for some reason? There
hasn't traditionally been drop-frame rates for 23.976. I'm not sure why this
is, but I'd guess it's because feature films [...]
Allright. Because ffmpeg doesnt have frame-accurate seeking we can
only calculate gop and play with the proprietary hh:mm:ss.ms values of
-ss and -t.

As the frame rate has been an excuse from the beginning, I've recoded
the file with:
# ./ffmpeg -i ./lordoftherings_h640_ml.mov -vcodec libx264 -r 25 -g
50 -vpre default ./lord25.mp4

This means we now have:
25 fps
111.28 sec length
keyframes every 2 sec. or 50 frames
h264

But:
Duration: 00:01:51.28, start: 0.000000, bitrate: 261 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 640x272, 196 kb/s, 25 fps,
25 tbr, 25 tbn, 50 tbc
Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 58 kb/s

50tbc ?? I'm clueless here.. also this:
" Seems stream 0 codec frame rate differs from container frame rate:
50.00 (50/1) -> 25.00 (25/1)"
Where did 50 come from?


Let's split.......
Half of the video is somewhere around 54 sec and it should be keyframe
so let's do it:
# ffmpeg -y -t 54 -i lord25.mp4 -acodec copy -vcodec copy lord25-half1.mp4
# ffmpeg -y -ss 54 -i lord25.mp4 -acodec copy -vcodec copy lord25-half2.mp4

And the results are in:
1. Duration: 00:00:56.28 (???)
2. Duration: 00:00:59.20 (that gives us a total of 115.48 seconds)


I guess it means that -t 54 triggered jump to another keyframe. Let's
try the last frame before 54 -t 53.9999:
# ffmpeg -y -t 53.99999 -i lord25.mp4 -acodec copy -vcodec copy
lord25-half1-1.mp4
Duration: 00:00:56.28
Still wrong.

Let's try -t 53:
# ffmpeg -y -t 53 -i lord25.mp4 -acodec copy -vcodec copy lord25-half1-2.mp4
Duration: 00:00:55.24
Wrong again

However, when observing the output from encoder it states:
frame= 1325 fps= 0 q=-1.0 Lsize= 2092kB time=55.17 bitrate= 310.6kbits/s
video:1697kB audio:357kB global headers:0kB muxing overhead 1.840558%

This means that the -t 53 correctly translates to 1325th frames (with 25fps).

Any ideas?
--
__
/.)\ +48 695 600 936
\(./ abodera at gmail.com
Dave P
2010-01-06 22:33:01 UTC
Permalink
Post by Artur Bodera
Post by Phil Rhodes
That said none of this will help you with such an oddball frame rate.
Where'd you get this file - is it double-rate 23.976 for some reason? There
hasn't traditionally been drop-frame rates for 23.976. I'm not sure why this
is, but I'd guess it's because feature films [...]
Allright. Because ffmpeg doesnt have frame-accurate seeking we can
only calculate gop and play with the proprietary hh:mm:ss.ms values of
-ss and -t.
As the frame rate has been an excuse from the beginning, I've recoded
# ?./ffmpeg -i ./lordoftherings_h640_ml.mov -vcodec libx264 -r 25 -g
50 -vpre default ./lord25.mp4
? ?25 fps
? ?111.28 sec length
? ?keyframes every 2 sec. or 50 frames
? ?h264
?Duration: 00:01:51.28, start: 0.000000, bitrate: 261 kb/s
? ?Stream #0.0(eng): Video: h264, yuv420p, 640x272, 196 kb/s, 25 fps,
25 tbr, 25 tbn, 50 tbc
? ?Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 58 kb/s
50.00 (50/1) -> 25.00 (25/1)"
Where did 50 come from?
Let's split.......
Half of the video is somewhere around 54 sec and it should be keyframe
# ffmpeg -y -t 54 -i lord25.mp4 -acodec copy -vcodec copy lord25-half1.mp4
# ffmpeg -y -ss 54 -i lord25.mp4 -acodec copy -vcodec copy lord25-half2.mp4
1. Duration: 00:00:56.28 ?(???)
2. Duration: 00:00:59.20 ?(that gives us a total of 115.48 seconds)
I guess it means that -t 54 triggered jump to another keyframe. Let's
# ffmpeg -y -t 53.99999 -i lord25.mp4 -acodec copy -vcodec copy
lord25-half1-1.mp4
Duration: 00:00:56.28
Still wrong.
# ffmpeg -y -t 53 -i lord25.mp4 -acodec copy -vcodec copy lord25-half1-2.mp4
Duration: 00:00:55.24
Wrong again
frame= 1325 fps= ?0 q=-1.0 Lsize= ? ?2092kB time=55.17 bitrate= 310.6kbits/s
video:1697kB audio:357kB global headers:0kB muxing overhead 1.840558%
This means that the -t 53 correctly translates to 1325th frames (with 25fps).
Any ideas?
Scene changes could be inserting keyframes automatically. Perhaps
playing around with -sc_threshold you could generate more consistent
GOPs. If you're re-encoding just to make cuts, and the re-encode is
disposable, why not make it I-frames only? Then seeking would be far
more accurate.
Artur Bodera
2010-01-07 10:50:48 UTC
Permalink
If you're re-encoding just to make cuts, [...]
I'm not. It's only for testing purposes. If I'm lucky I'll be able to
probe the gop from the file I want to cut, but that's about it.
Decoding to raw or iframes or frame images then encoding again is too
expensive. I want to know how to cut it in half within existing stream
(hence -acodec copy -vcodec copy).

sc_threshold will probably affect the gop, but it will not help me if
I don't know if scene changes.

But logically -t x and -ss x should work.... -t x should crop video
to nearest keyframe (to x), an -ss x should seek to nearest keyframe
(to x). Regardles if it's 54, 55, 55.5 or 56th second. Why then am I
getting overlapped chunks?
--
__
/.)\ +48 695 600 936
\(./ abodera at gmail.com
belcampo
2010-01-07 14:43:35 UTC
Permalink
Post by Artur Bodera
If you're re-encoding just to make cuts, [...]
I'm not. It's only for testing purposes. If I'm lucky I'll be able to
probe the gop from the file I want to cut, but that's about it.
Decoding to raw or iframes or frame images then encoding again is too
expensive. I want to know how to cut it in half within existing stream
(hence -acodec copy -vcodec copy).
sc_threshold will probably affect the gop, but it will not help me if
I don't know if scene changes.
But logically -t x and -ss x should work.... -t x should crop video
to nearest keyframe (to x), an -ss x should seek to nearest keyframe
(to x). Regardles if it's 54, 55, 55.5 or 56th second. Why then am I
getting overlapped chunks?
I think you need to reed my former answer. -ss means movie-time not
video-time
Innertia
2011-12-22 02:46:28 UTC
Permalink
Hi ^^ I'm also seeking the way to split video accurately enough as possible.
um, I think -ss and -t is not enough to do it.
let's assume that if I have a 10:00 length video file, and I want to split
it into two parts, one is of length of 5:00, and the other is of also 5:00;
but if there're keyframes located at 4:55 and 5:05, ffmpeg must be trying to
seek keyframe to split. I want to say that first part will be accurately
5:00, and second one will be 5:05 becuase of the fact that delta frames near
the end border have their key frame, so there's no problem.
but when second one trying to start at 5:00, it will recognize that there's
no key frame to refer to start and make perfect frame, so it will ignore the
-ss 00:05:00 option;

I believe there's no way yet to avoid the duplication when splitting...only
we can fix and customize the ffmpeg source;; and that's what I'm doing
recently(that's too difficult to do...it's out of my ability (T.T)~~I just
hope any brilliant developers help us~!)



--
View this message in context: http://ffmpeg-users.933282.n4.nabble.com/Frame-gop-accurate-video-splitting-fps-gop-length-known-tp989756p4224028.html
Sent from the FFmpeg-users mailing list archive at Nabble.com.

Jan Stary
2010-01-06 11:39:58 UTC
Permalink
Post by Artur Bodera
[...]
? 1)? ~30s (00:00:00 - 00:00:30)
? 2)? ~10s (00:00:30 - 00:00:40)
? 3)? ~71s (00:00:40 - 00:01:51)
? Duration: 00:01:51.27, start: 0.000000, bitrate: 256 kb/s
??? Stream #0.0(eng): Video: h264, yuv420p, 640x272, 192 kb/s, 47.90 fps,
23.98 tbr, 24k tbn, 47.95 tbc
??? Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 58 kb/s
If I remember correctly, the file 'lord.mp4' was transcoded
from a *.mov original as follows:

ffmpeg -i ./lordoftherings_h640_ml.mov -vcodec libx264 -g 50 ./lord.mp4

Why do you transcode it at all? Doesn't this reduce the audio/video
quality quite a bit? Does the same happen if you transcode with
a bitrate higher then the cheap default? And if you leave out
the "-g 50"?

Anyway, does the same happen if you cut the MOV original into pieces
instead of the (possibly crappy) MP4 transcode?

Can you give us the original MOV file (01:51, can't be that big).
Post by Artur Bodera
ffmpeg -y -t 30 -i lord.mp4 -vcodec copy -acodec copy lord-c1.mp4
Duration: 00:00:30.05, start: 0.000000, bitrate: 286 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 640x272, 237 kb/s, 47.95
fps, 23.98 tbr, 48k tbn, 47.95 tbc
Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 43 kb/s
ffmpeg -y -ss 30 -t 10 -i lord.mp4 -vcodec copy -acodec copy lord-c2.mp4
Duration: 00:00:15.27, start: 0.000000, bitrate: 226 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 640x272, 156 kb/s, 47.95
fps, 23.98 tbr, 48k tbn, 47.95 tbc
Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 64 kb/s
ffmpeg -y -ss 40 -i lord.mp4 -vcodec copy -acodec copy lord-c3.mp4
Duration: 00:01:12.12, start: 0.000000, bitrate: 268 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 640x272, 199 kb/s, 47.95
fps, 23.98 tbr, 48k tbn, 47.95 tbc
Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 63 kb/s
After re-joining the video has 117.44 s (the original file had 111,27s).
The fragments are inaccurate and overlap.
--
__
/.)\ +48 695 600 936
\(./ abodera at gmail.com
_______________________________________________
ffmpeg-user mailing list
ffmpeg-user at mplayerhq.hu
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Artur Bodera
2010-01-06 12:18:49 UTC
Permalink
Post by Jan Stary
If I remember correctly, the file 'lord.mp4' was transcoded
ffmpeg -i ./lordoftherings_h640_ml.mov -vcodec libx264 -g 50 ./lord.mp4
Why do you transcode it at all? Doesn't this reduce the audio/video
quality quite a bit? Does the same happen if you transcode with
a bitrate higher then the cheap default? And if you leave out
the "-g 50"?
Well basically I'm looking for an universal way to calculate timecodes
and cut any arbitrary length video.
I just want to be able to cut any video in half or to more pieces in a
way precise enough, so I can re-join the fragments later and still
have the same video.

The transcoding has been performed only for testing purposes - this
way we know gop is exactly 50. It would be pointless to test -ss and
-t with some exotic files encoded with god-knows-what and try to probe
it with ffprobe.

You can take any video file and transcode it with the same command
line - then try to split it.

If ffmpeg can't properly handle it's own files (encoded by ffmpeg)
then I'm doing someting wrong or there's a bug.


Nevertheless, here are the test files:
lord.mp4 - http://www.ementor.pl/ffmpeg-split/lord.mp4
lord-c1.mp4 - http://www.ementor.pl/ffmpeg-split/lord-c1.mp4
lord-c2.mp4 - http://www.ementor.pl/ffmpeg-split/lord-c2.mp4
lord-c3.mp4 - http://www.ementor.pl/ffmpeg-split/lord-c3.mp4
--
--
__
/.)\ +48 695 600 936
\(./ abodera at gmail.com
Jan Stary
2010-01-06 12:32:14 UTC
Permalink
Post by Artur Bodera
Post by Jan Stary
If I remember correctly, the file 'lord.mp4' was transcoded
ffmpeg -i ./lordoftherings_h640_ml.mov -vcodec libx264 -g 50 ./lord.mp4
Why do you transcode it at all? Doesn't this reduce the audio/video
quality quite a bit? Does the same happen if you transcode with
a bitrate higher then the cheap default? And if you leave out
the "-g 50"?
Well basically I'm looking for an universal way to calculate timecodes
and cut any arbitrary length video.
I just want to be able to cut any video in half or to more pieces in a
way precise enough, so I can re-join the fragments later and still
have the same video.
The transcoding has been performed only for testing purposes - this
way we know gop is exactly 50. It would be pointless to test -ss and
-t with some exotic files encoded with god-knows-what and try to probe
it with ffprobe.
You can take any video file and transcode it with the same command
line - then try to split it.
If ffmpeg can't properly handle it's own files (encoded by ffmpeg)
then I'm doing someting wrong or there's a bug.
Can you give us the original MOV file?
Post by Artur Bodera
lord.mp4 - http://www.ementor.pl/ffmpeg-split/lord.mp4
$ ftp http://www.ementor.pl/ffmpeg-split/lord.mp4
$ ffmpeg -i lord.mp4
FFmpeg version SVN-r13839, Copyright (c) 2000-2008 Fabrice Bellard, et al.
configuration: --enable-shared --cc=cc --mandir=/usr/local/man --disable-debug --disable-optimizations --enable-gpl --enable-pthreads --enable-postproc --enab le-swscale --enable-liba52 --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-x11grab --extra -libs=-L/usr/local/lib -L/usr/X11R6/lib --extra-cflags=-I/usr/local/include -I/u sr/X11R6/include --disable-decoder=cavs --disable-altivec --disable-armv6 --disable-armvfp --disable-iwmmxt --disable-neon
libavutil version: 49.7.0
libavcodec version: 51.57.2
libavformat version: 52.16.0
libavdevice version: 52.0.0
built on Jul 1 2009 12:49:39, gcc: 3.3.5 (propolice)

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x2fc58c70]edit list not starting at 0,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
a/v desync might occur, patch welcome
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'lord.mp4':
Duration: 00:01:51.27, start: 0.000000, bitrate: 268 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 640x272, 23.98 tb(r)
Stream #0.1(eng): Audio: libfaad, 48000 Hz, stereo
Must supply at least one output file


while your ffmpeg -i lord.mp4 says
Post by Artur Bodera
Duration: 00:01:51.27, start: 0.000000, bitrate: 256 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 640x272, 192 kb/s, 47.90 fps,
23.98 tbr, 24k tbn, 47.95 tbc
Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 58 kb/s
We might have different versions installed,
but is it actually the same file?

Something's wrong with the copy of lord.mp4 you gave us.
Jan Stary
2010-01-06 12:42:26 UTC
Permalink
Also,
Post by Artur Bodera
lord-c1.mp4 - http://www.ementor.pl/ffmpeg-split/lord-c1.mp4
$ ftp http://www.ementor.pl/ffmpeg-split/lord-c1.mp4
$ ffmpeg -i lord-c1.mp4
FFmpeg version SVN-r13839, Copyright (c) 2000-2008 Fabrice Bellard, et al.
configuration: --enable-shared --cc=cc --mandir=/usr/local/man --disable-debug --disable-optimizations --enable-gpl --enable-pthreads --enable-postproc --enable-swscale --enable-liba52 --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-x11grab --extra-libs=-L/usr/local/lib -L/usr/X11R6/lib --extra-cflags=-I/usr/local/include -I/usr/X11R6/include --disable-decoder=cavs --disable-altivec --disable-armv6 --disable-armvfp --disable-iwmmxt --disable-neon
libavutil version: 49.7.0
libavcodec version: 51.57.2
libavformat version: 52.16.0
libavdevice version: 52.0.0
built on Jul 1 2009 12:49:39, gcc: 3.3.5 (propolice)

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x2aac7c70]edit list not starting at 0, a/v desync might occur, patch welcome

Seems stream 0 codec frame rate differs from container frame rate: 24000.00 (48000/2) -> 23.98 (24000/1001)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'lord-c1.mp4':
Duration: 00:00:30.05, start: 0.000000, bitrate: 286 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 640x272, 23.98 tb(r)
Stream #0.1(eng): Audio: libfaad, 48000 Hz, stereo
Must supply at least one output file

which again differs from what you report.
(Should I try with latest svn?)
Artur Bodera
2010-01-06 13:08:26 UTC
Permalink
Post by Jan Stary
$ ffmpeg -i lord-c1.mp4
FFmpeg version SVN-r13839, Copyright (c) 2000-2008 Fabrice Bellard, et al.
?configuration: --enable-shared --cc=cc --mandir=/usr/local/man --disable-debug --disable-optimizations --enable-gpl --enable-pthreads --enable-postproc --enable-swscale --enable-liba52 --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-x11grab --extra-libs=-L/usr/local/lib -L/usr/X11R6/lib --extra-cflags=-I/usr/local/include -I/usr/X11R6/include --disable-decoder=cavs --disable-altivec --disable-armv6 --disable-armvfp --disable-iwmmxt --disable-neon
?libavutil version: 49.7.0
?libavcodec version: 51.57.2
?libavformat version: 52.16.0
?libavdevice version: 52.0.0
?built on Jul ?1 2009 12:49:39, gcc: 3.3.5 (propolice)
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
Seems stream 0 codec frame rate differs from container frame rate: 24000.00 (48000/2) -> 23.98 (24000/1001)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
?Duration: 00:00:30.05, start: 0.000000, bitrate: 286 kb/s
? ?Stream #0.0(eng): Video: h264, yuv420p, 640x272, 23.98 tb(r)
? ?Stream #0.1(eng): Audio: libfaad, 48000 Hz, stereo
Must supply at least one output file
which again differs from what you report.
(Should I try with latest svn?)
I don't see the difference:
# ffmpeg -i lord-c1.mp4
FFmpeg version SVN-r20880, Copyright (c) 2000-2009 Fabrice Bellard, et al.
built on Dec 22 2009 20:38:09 with gcc 4.3.2 20081105 (Red Hat 4.3.2-7)
configuration: --prefix=/usr --incdir=/usr/include --libdir=/usr/lib
--mandir=/usr/share/man --shlibdir=/usr/lib --enable-libfaac
--enable-libfaad --enable-libgsm --enable-libmp3lame
--enable-libtheora --enable-libvorbis --enable-libx264
--enable-libxvid --enable-x11grab --enable-avfilter --enable-postproc
--enable-pthreads --enable-gpl --enable-debug --enable-avfilter
--enable-avfilter-lavf --enable-nonfree
libavutil 50. 7. 0 / 50. 7. 0
libavcodec 52.43. 0 / 52.43. 0
libavformat 52.43. 0 / 52.43. 0
libavdevice 52. 2. 0 / 52. 2. 0
libavfilter 1.12. 0 / 1.12. 0
libswscale 0. 7. 2 / 0. 7. 2
libpostproc 51. 2. 0 / 51. 2. 0

Seems stream 0 codec frame rate differs from container frame rate:
47.95 (48000/1001) -> 23.98 (24000/1001)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'lord-c1.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf52.43.0
Duration: 00:00:30.05, start: 0.000000, bitrate: 286 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 640x272, 237 kb/s, 47.95
fps, 23.98 tbr, 48k tbn, 47.95 tbc
Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 43 kb/s
At least one output file must be specified
--
__
/.)\ +48 695 600 936
\(./ abodera at gmail.com
Loading...