Lossless cut from a h264 video with audio

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Lossless cut from a h264 video with audio

Samat Galimov
Hello,

tl;dr: Q: is there a way to cut a 10 second clip from a h264 video (downloaded from youtube) to later use it in web browsers with no quality loss?

What I have tried so far: http://alpha.rawg.io/question/

Long version:

My inputs are http://alpha.rawg.io/question/cook.txt <http://alpha.rawg.io/question/cook.txt>

My first attempt is to opt-in for copy codecs using the following command:

        /usr/bin/env ffmpeg -y -ss 0:03:18 -t 0:00:10 -i cook.mp4 -c copy cook-start.mp4 &> cook-start.txt

What I've got is:
- Safari: audio/video sync is OK, beginning is OK, but additional 3 seconds of audio without video in the end
- Chrome: audio/video is out of sync

Then I tried to specify -ss as an output option:

        /usr/bin/env ffmpeg -y -i cook.mp4 -ss 0:03:18 -t 0:00:10 -c copy cook-end.mp4 &> cook-end.txt

Safari & Chrome: first 3 seconds have no video, but audio only.


Is there a clever trick to overcome this apparent keyframe location issue while not re-encoding videos?

If there is no way to avoid re-encoding, what options should I use to minimise quality loss?

Here is the webpage to check out my results & source files: https://alpha.rawg.io/question/ <https://alpha.rawg.io/question/>

Thank you very much in advance.

Samat.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Lossless cut from a h264 video with audio

DopeLabs
try this one...


/usr/bin/env ffmpeg -y -ss 0:03:18  -i cook.mp4 -t 0:00:10 -c copy cook-start.mp4 &> cook-start.txt



> On Oct 10, 2018, at 8:44 56AM, Samat Galimov <[hidden email]> wrote:
>
> Hello,
>
> tl;dr: Q: is there a way to cut a 10 second clip from a h264 video (downloaded from youtube) to later use it in web browsers with no quality loss?
>
> What I have tried so far: http://alpha.rawg.io/question/
>
> Long version:
>
> My inputs are http://alpha.rawg.io/question/cook.txt <http://alpha.rawg.io/question/cook.txt>
>
> My first attempt is to opt-in for copy codecs using the following command:
>
> /usr/bin/env ffmpeg -y -ss 0:03:18 -t 0:00:10 -i cook.mp4 -c copy cook-start.mp4 &> cook-start.txt
>
> What I've got is:
> - Safari: audio/video sync is OK, beginning is OK, but additional 3 seconds of audio without video in the end
> - Chrome: audio/video is out of sync
>
> Then I tried to specify -ss as an output option:
>
> /usr/bin/env ffmpeg -y -i cook.mp4 -ss 0:03:18 -t 0:00:10 -c copy cook-end.mp4 &> cook-end.txt
>
> Safari & Chrome: first 3 seconds have no video, but audio only.
>
>
> Is there a clever trick to overcome this apparent keyframe location issue while not re-encoding videos?
>
> If there is no way to avoid re-encoding, what options should I use to minimise quality loss?
>
> Here is the webpage to check out my results & source files: https://alpha.rawg.io/question/ <https://alpha.rawg.io/question/>
>
> Thank you very much in advance.
>
> Samat.
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Lossless cut from a h264 video with audio

Martin Underwood
>> Q: is there a way to cut a 10 second clip from a h264 video (downloaded
>> from youtube) to later use it in web browsers with no quality loss?

> try this one...
> /usr/bin/env ffmpeg -y -ss 0:03:18  -i cook.mp4 -t 0:00:10 -c copy
> cook-start.mp4 &> cook-start.txt


Does ffmpeg suffer from the same problem as AVIdemux that cuts must be made
on a GOP boundary in order for the cut to be clean? Or does it recode a few
full and differential frames so that the second clip of a cut always starts
with a full frame followed by regenerated differential frames *wrt that full
frame*, until the next full frame in the source video, like VideoReDo does?

Apologies for terms full and differential, but I can never remember which
are I, B and P frames.

Is MPEG2 more prone to this problem than H264?

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Lossless cut from a h264 video with audio

Samat Galimov
In reply to this post by DopeLabs
exactly same result as 'cook-start', i.e.

/usr/bin/env ffmpeg -y -ss 0:03:18 -t 0:00:10 -i cook.mp4 -c copy cook-start.mp4 &> cook-start.txt; # ss input option


> On 10 Oct 2018, at 19:30, DopeLabs <[hidden email]> wrote:
>
> try this one...
>
>
> /usr/bin/env ffmpeg -y -ss 0:03:18  -i cook.mp4 -t 0:00:10 -c copy cook-start.mp4 &> cook-start.txt
>
>
>
>> On Oct 10, 2018, at 8:44 56AM, Samat Galimov <[hidden email] <mailto:[hidden email]>> wrote:
>>
>> Hello,
>>
>> tl;dr: Q: is there a way to cut a 10 second clip from a h264 video (downloaded from youtube) to later use it in web browsers with no quality loss?
>>
>> What I have tried so far: http://alpha.rawg.io/question/
>>
>> Long version:
>>
>> My inputs are http://alpha.rawg.io/question/cook.txt <http://alpha.rawg.io/question/cook.txt><http://alpha.rawg.io/question/cook.txt <http://alpha.rawg.io/question/cook.txt>>
>>
>> My first attempt is to opt-in for copy codecs using the following command:
>>
>> /usr/bin/env ffmpeg -y -ss 0:03:18 -t 0:00:10 -i cook.mp4 -c copy cook-start.mp4 &> cook-start.txt
>>
>> What I've got is:
>> - Safari: audio/video sync is OK, beginning is OK, but additional 3 seconds of audio without video in the end
>> - Chrome: audio/video is out of sync
>>
>> Then I tried to specify -ss as an output option:
>>
>> /usr/bin/env ffmpeg -y -i cook.mp4 -ss 0:03:18 -t 0:00:10 -c copy cook-end.mp4 &> cook-end.txt
>>
>> Safari & Chrome: first 3 seconds have no video, but audio only.
>>
>>
>> Is there a clever trick to overcome this apparent keyframe location issue while not re-encoding videos?
>>
>> If there is no way to avoid re-encoding, what options should I use to minimise quality loss?
>>
>> Here is the webpage to check out my results & source files: https://alpha.rawg.io/question/ <https://alpha.rawg.io/question/><https://alpha.rawg.io/question/ <https://alpha.rawg.io/question/>>
>>
>> Thank you very much in advance.
>>
>> Samat.
>> _______________________________________________
>> ffmpeg-user mailing list
>> [hidden email] <mailto:[hidden email]>
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-user <http://ffmpeg.org/mailman/listinfo/ffmpeg-user>
>>
>> To unsubscribe, visit link above, or email
>> [hidden email] <mailto:[hidden email]> with subject "unsubscribe".
>
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email] <mailto:[hidden email]>
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user <http://ffmpeg.org/mailman/listinfo/ffmpeg-user>
>
> To unsubscribe, visit link above, or email
> [hidden email] <mailto:[hidden email]> with subject "unsubscribe".

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

How to add 4 streams to one YouTube channel???

Rad J
Hi There,

I was able to find a way to stream 2 channels to one YouTube channel using
the following command line:

ffmpeg -rtsp_transport tcp -i "rtsp://
web1:pass@10.10.10.125:554/cam/realmonitor?channel=1&subtype=0" -i "rtsp://
web1:pass@10.10.10.125:554/cam/realmonitor?channel=2&subtype=0" -f lavfi -i
anullsrc -filter_complex "[0:v] setpts=PTS-STARTPTS,
scale=800x448,setsar=1[upperleft]; [1:v] setpts=PTS-STARTPTS,
scale=800x448,setsar=1[upperright]; [upperleft][upperright]hstack[base]"
-map [base] -map 2 -f flv rtmp://
x.rtmp.youtube.com/live2/xxxx-xxxx-xxxx-xxxx

Any idea how to make it better quality and how to add 2 more sources???

Any assistance is appreciated!

Thank you!
-Zark
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to add 4 streams to one YouTube channel???

Moritz Barsnick
On Wed, Oct 10, 2018 at 15:00:30 -0500, Rad J wrote:
> Any idea how to make it better quality and how to add 2 more sources???

Did you not see this answer in September?
http://ffmpeg.org/pipermail/ffmpeg-user/2018-September/041119.html

Moritz
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to add 4 streams to one YouTube channel???

Rad J
Yes thank you that worked well, but I decided to got with two YouTube
live channels and 2 streams per channel do to the quality.

However I'm having some issues with the stream quality and frame loss...
also YouTube is complaining about my stream type...

This is what I'm getting:

*Bad video settings*
*The video is encoded with an unsupported codec. Please set the video codec
for the stream to a supported codec (H.264).*

*10:54 PM Bad Bad video settings*
*The video is encoded with an unsupported codec. Please set the video codec
for the stream to a supported codec (H.264).*
*Please check the video resolution. The current resolution is (3840x1080),
which is not optimal.*
*The stream's current bitrate (992.00 Kbps) is lower than the recommended
bitrate. We recommend that you use a stream bitrate of 4500 Kbps.*

Do you know how to fix this? How to increase the bitrate?

Thanks,
Rad


On Wed, Oct 10, 2018 at 4:46 PM Moritz Barsnick <[hidden email]> wrote:

> On Wed, Oct 10, 2018 at 15:00:30 -0500, Rad J wrote:
> > Any idea how to make it better quality and how to add 2 more sources???
>
> Did you not see this answer in September?
> http://ffmpeg.org/pipermail/ffmpeg-user/2018-September/041119.html
>
> Moritz
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to add 4 streams to one YouTube channel???

Moritz Barsnick
On Mon, Oct 15, 2018 at 23:04:39 -0500, Rad J wrote:
> However I'm having some issues with the stream quality and frame loss...
> also YouTube is complaining about my stream type...

You sometimes need to fiddle against YouTube's expectation. I remember
that YouTube didn't see my live stream actually starting, without
giving me detailed errors like yours. When I improved some parameters
(such as GOP size), it suddenly worked.

> This is what I'm getting:
>
> *Bad video settings*
> *The video is encoded with an unsupported codec. Please set the video codec
> for the stream to a supported codec (H.264).*
>
> *10:54 PM Bad Bad video settings*
> *The video is encoded with an unsupported codec. Please set the video codec
> for the stream to a supported codec (H.264).*
> *Please check the video resolution. The current resolution is (3840x1080),
> which is not optimal.*
> *The stream's current bitrate (992.00 Kbps) is lower than the recommended
> bitrate. We recommend that you use a stream bitrate of 4500 Kbps.*
>
> Do you know how to fix this? How to increase the bitrate?

Sure we know. But please show your currently used command line(s) which
provoke(s) these warnings. We can try to fine-tune or reproduce.

Cheers,
Moritz
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to add 4 streams to one YouTube channel???

DopeLabs
an option you may wish to explore if you have the available network and encoding resources is youtube live streaming support for multiple cameras for a single livestream. each 'camera' has its own rtmp ingestion url and stream key and the viewer can choose which of the cameras they want to watch. multiple cameras show up as thumbnails above the main video.


https://support.google.com/youtube/answer/2853812?hl=en

cheers,
DL

> On Oct 16, 2018, at 4:27 58AM, Moritz Barsnick <[hidden email]> wrote:
>
> On Mon, Oct 15, 2018 at 23:04:39 -0500, Rad J wrote:
>> However I'm having some issues with the stream quality and frame loss...
>> also YouTube is complaining about my stream type...
>
> You sometimes need to fiddle against YouTube's expectation. I remember
> that YouTube didn't see my live stream actually starting, without
> giving me detailed errors like yours. When I improved some parameters
> (such as GOP size), it suddenly worked.
>
>> This is what I'm getting:
>>
>> *Bad video settings*
>> *The video is encoded with an unsupported codec. Please set the video codec
>> for the stream to a supported codec (H.264).*
>>
>> *10:54 PM Bad Bad video settings*
>> *The video is encoded with an unsupported codec. Please set the video codec
>> for the stream to a supported codec (H.264).*
>> *Please check the video resolution. The current resolution is (3840x1080),
>> which is not optimal.*
>> *The stream's current bitrate (992.00 Kbps) is lower than the recommended
>> bitrate. We recommend that you use a stream bitrate of 4500 Kbps.*
>>
>> Do you know how to fix this? How to increase the bitrate?
>
> Sure we know. But please show your currently used command line(s) which
> provoke(s) these warnings. We can try to fine-tune or reproduce.
>
> Cheers,
> Moritz
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to add 4 streams to one YouTube channel???

Rad J
In reply to this post by Moritz Barsnick
Hello Mortiz,

Thanks for getting back to me so quickly! Here is my command line I
currently use:

ffmpeg -rtsp_transport tcp
-i "rtsp://xxxx:xxxx@10.1.10.125:554/cam/realmonitor?channel=1&subtype=0"
-i "rtsp://xxxx:xxxx@10.1.10.125:554/cam/realmonitor?channel=2&subtype=0"
-f lavfi -i anullsrc -filter_complex "
[0:v] setpts=PTS-STARTPTS, scale=1920x1080,setsar=1[upperleft];
[1:v] setpts=PTS-STARTPTS, scale=1920x1080,setsar=1[upperright];
[upperleft][upperright]hstack[base]" -map [base] -map 2
*-b 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k    <-- I just added
that, but does not seem to help*
-f flv rtmp://x.rtmp.youtube.com/live2/xxxx-xxxx-xxxx-xxxx

And here is the live stream on YouTube:

https://www.youtube.com/watch?v=Z5ZMPCuDAKA

Another thing that also keeps happening is that the stream just freezes up
after 24hrs or so...
I have to stop and restart the command to get it going again.... :(

https://www.screencast.com/t/ZgPhP8vMAz

And after I restart I keep getting bunch of errors (that's normal tho... it
still works, but can I fix those?)

https://www.screencast.com/t/DRuWBg3zDi

Thanks,
Rad


On Tue, Oct 16, 2018 at 6:28 AM Moritz Barsnick <[hidden email]> wrote:

> On Mon, Oct 15, 2018 at 23:04:39 -0500, Rad J wrote:
> > However I'm having some issues with the stream quality and frame loss...
> > also YouTube is complaining about my stream type...
>
> You sometimes need to fiddle against YouTube's expectation. I remember
> that YouTube didn't see my live stream actually starting, without
> giving me detailed errors like yours. When I improved some parameters
> (such as GOP size), it suddenly worked.
>
> > This is what I'm getting:
> >
> > *Bad video settings*
> > *The video is encoded with an unsupported codec. Please set the video
> codec
> > for the stream to a supported codec (H.264).*
> >
> > *10:54 PM Bad Bad video settings*
> > *The video is encoded with an unsupported codec. Please set the video
> codec
> > for the stream to a supported codec (H.264).*
> > *Please check the video resolution. The current resolution is
> (3840x1080),
> > which is not optimal.*
> > *The stream's current bitrate (992.00 Kbps) is lower than the recommended
> > bitrate. We recommend that you use a stream bitrate of 4500 Kbps.*
> >
> > Do you know how to fix this? How to increase the bitrate?
>
> Sure we know. But please show your currently used command line(s) which
> provoke(s) these warnings. We can try to fine-tune or reproduce.
>
> Cheers,
> Moritz
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".