Re: [FFmpeg-user] MPEG 'broken_link' flag -- How do I set it?

2024-03-25 Thread Mark Filipak

Thank you, Mark.

On 25/03/2024 16.45, Mark Thompson wrote:

On 24/03/2024 15:48, Mark Filipak wrote:
I cut at the end of an open GOP. When I did that, FFmpeg did not set the MPEG 'broken_link' flag 
to '1'.


The frame following the cut has to be flagged:
'closed_gop' = '0' because it's an open GOP, also, and
'broken_link' = '1'.


How do I do that? I searched but did not find.


The ffmpeg utility does not edit the internals of the bitstream when cutting (packets are 
effectively opaque to it); you would need a BSF to make this change.


Yes, a bit stream filter is what I seek.

Making such a BSF should be straightforward: use CBS BSF with a single update_fragment function 
which edits the GOP header on any I frame with a discontinuity before it.


What's a CBS bit stream filter?

There's 2 segments, so 4 cuts. They are both 100% open GOPs. The concatenation is 6 seconds of 
video. There are 29 GOPs. As you can see, all 29 have identical GOPs. My parse shows that they claim 
to be closed and not broken. That is 100% false. The use of packet time codes is obsolete, but the 
'closed_gop' & 'broken_link' flags aren't.


00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47
00 00 01 B8 41 A2 95 47

GOP_start_code 00 00 01 B8
time_code  == == == == 41 A2 95 47   //Re: H.262 §6.3.8
 .—' '—.
drop_frame_flag  0---          //'1': drop, '0' 
don't drop
time_code_hours  -100 00--         //= 16
time_code_minutes --01 1010        //= 26
marker_bit      0---    
time_code_seconds   -010 100-      //= 20
time_code_pictures       ---1 0101 0---    //= 42; time 
code = 16:26:20.42
closed_gop         -1--    //'1': closed 
GOP; '0': open GOP
broken_link        --0-    //'1': GOP edited, B-frames have lost 
their reference frames; '0': GOP not edited

?      ---0 0111



___
ffmpeg-user mailing list
ffmpeg-user@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-user] MPEG 'broken_link' flag -- How do I set it?

2024-03-25 Thread Mark Thompson

On 24/03/2024 15:48, Mark Filipak wrote:

I cut at the end of an open GOP. When I did that, FFmpeg did not set the MPEG 
'broken_link' flag to '1'.

The frame following the cut has to be flagged:
'closed_gop' = '0' because it's an open GOP, also, and
'broken_link' = '1'.


How do I do that? I searched but did not find.


The ffmpeg utility does not edit the internals of the bitstream when cutting 
(packets are effectively opaque to it); you would need a BSF to make this 
change.

Making such a BSF should be straightforward: use CBS BSF with a single 
update_fragment function which edits the GOP header on any I frame with a 
discontinuity before it.

- Mark
___
ffmpeg-user mailing list
ffmpeg-user@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-user] Possible to speed up/down video while keeping audio pitch?

2024-03-25 Thread Bo Berglund
On Mon, 25 Mar 2024 07:04:37 +0100, Bo Berglund  wrote:

>I found the syntax as an example at
>
>http://trac.ffmpeg.org/wiki/How%20to%20speed%20up%20/%20slow%20down%20a%20video
> 
>
>so I made a test.
>
>Note: Newsreader is doing the line wrap, it is on a single line of course:
>
>ffmpeg -hide_banner -i input.mp4 -filter_complex
>"[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" output.mp4
>
>It took 6 s to encode a 76 s mp4 video into a 38 s sped up video.
>
>So it seems like one must apply the inverse factor on setpts and atempo, i.e.
>change audio tempo by the inverse of the video speed.
>
>I tested it with speedups of 2.0 and 1.25 and both worked OK.
>
>So I will package this into a speedchange script among the other video 
>utilities
>scripts I have created.

So while this works it takes a pretty long time to process. :(

Question:

Can this be integrated in the download script I use to retrieve the video in the
first place?
I have included a tweak to get the keyframes synced to whole seconds etc already
so the video can be edited on 1 s borders without getting artifacts at the
borders. It looks like this for download (again one single line command):

ffmpeg -hide_banner ${MODE} -i \"${M3U8URL}\" -r 30 -vf scale=w=-4:h=${VIDEORES}
-c:v libx264 -preset fast -crf 26 -x264-params keyint=30:scenecut=0:open-gop=0
-c:a aac -t ${CAPTURETIME} ${TARGETFILE}

Where

MODE="-referer \"${VIDEOURL}\""
M3U8URL=the m3u8 streaming URL of the source
VIDEORES="480"
CAPTURETIME=the time in seconds to capture the video
TARGETFILE=the output result mp4 file

Can the speedchange be pushed into this such that everything can happen while
the video downloads? In that case the processing time does not matter since the
transfer speed is low anyway.

I.e. how to pipe the output of the download function into the following
processing before landing in the output file:

-filter_complex"[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]"


-- 
Bo Berglund
Developer in Sweden

___
ffmpeg-user mailing list
ffmpeg-user@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-user] Possible to speed up/down video while keeping audio pitch?

2024-03-25 Thread Michael Koch

Am 24.03.2024 um 23:30 schrieb Bo Berglund:

But is it possible also to modify an mp4 video file to *play* faster/slower than
original while keeping the accompanying audio pitch the same?


It's possible to change audio length, sample rate and pitch, and also 
all combinations of these three parameters.

See chapter 3.7 in my book:
http://www.astro-electronic.de/FFmpeg_Book.pdf

Michael

___
ffmpeg-user mailing list
ffmpeg-user@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-user] Possible to speed up/down video while keeping audio pitch?

2024-03-25 Thread Bo Berglund
On Mon, 25 Mar 2024 01:47:27 +0100, Paul B Mahol  wrote:

>On Mon, Mar 25, 2024 at 12:54?AM Laine Lee  wrote:
>
>>
>>
>> > On Mar 24, 2024, at 5:31?PM, Bo Berglund  wrote:
>> >
>> > ?I know how to use ffmpeg to adjust the video/audio sync and that is a
>> real
>> > simple command not requiring any remuxing or such. This is what I use in
>> my
>> > audiosync script and it runs very fast:
>> >
>> > ffmpeg -i $SOURCEFILE -itsoffset $DELAY -i $SOURCEFILE -map 1:v -map 0:a
>> -c copy
>> > $TARGETFILE
>> >
>> >
>> > But is it possible also to modify an mp4 video file to *play*
>> faster/slower than
>> > original while keeping the accompanying audio pitch the same?
>> >
>> > It *can* be done for instance in the VLC video player on playback, but
>> can one
>> > also modify the video file itself using ffmpeg so it will play at the
>> new speed
>> > while keeping audio recognizable (not Donald Duckie)?
>> >
>> > If so how is it done?
>> >
>> >
>> > --
>>
>> Sounds to me as though you want to change tempo of the audio stream. I
>> believe there’s a pipe from ffmpeg to Sox to handle it, but for that you
>> will extract audio, apply the tempo change, then remux. Changing tempo by a
>> factor greater than one reduces duration, and by a factor less than one
>> increases duration.
>>
>
>FFmpeg have tempo audio filter called atempo. No need to use obsolete SoX.
>
>

Thanks a bunch!

I found the syntax as an example at

http://trac.ffmpeg.org/wiki/How%20to%20speed%20up%20/%20slow%20down%20a%20video 

so I made a test.

Note: Newsreader is doing the line wrap, it is on a single line of course:

ffmpeg -hide_banner -i input.mp4 -filter_complex
"[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" output.mp4

It took 6 s to encode a 76 s mp4 video into a 38 s sped up video.

So it seems like one must apply the inverse factor on setpts and atempo, i.e.
change audio tempo by the inverse of the video speed.

I tested it with speedups of 2.0 and 1.25 and both worked OK.

So I will package this into a speedchange script among the other video utilities
scripts I have created.


-- 
Bo Berglund
Developer in Sweden

___
ffmpeg-user mailing list
ffmpeg-user@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".