Using ffmpeg to remove commercials from video file

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

Using ffmpeg to remove commercials from video file

jlundstocholm
I am trying to use ffmpeg to remove commercials from films I have recorded on my DVR. I have used the guide at http://www.joeldare.com/wiki/video:cut_video_with_ffmpeg .

So I am using it like this:

ffmpeg -ss 213 -i MySourceMovie.m4v testoutput.m4v

Above I would like to cut the first 213 seconds away from the video

The result is good with really good quality.

However - is there any way to prevent ffmpeg to run thru the entire video when doing this? For a TV-show with 2-3 commercial breaks it would take a couple of hours to process a 25-minute TV-show.

And - the command aboce results in a testoutput.m4v-file that contains what I would like to cut out. Is there any way that I can "reverse" this such that it results in the original video without the cut-out piece instead? Otherwise I would end up with a number of video files that I would need to stitch together again.

Thanks,



/Jesper
Copenhagen, Denmark
Reply | Threaded
Open this post in threaded view
|

Re: Using ffmpeg to remove commercials from video file

littlebat
On Wed, 14 Aug 2013 01:09:30 -0700 (PDT)
jlundstocholm <[hidden email]> wrote:

> I am trying to use ffmpeg to remove commercials from films I have
> recorded on my DVR. I have used the guide at
> http://www.joeldare.com/wiki/video:cut_video_with_ffmpeg .
>
> So I am using it like this:
>
> ffmpeg -ss 213 -i MySourceMovie.m4v testoutput.m4v
>
> Above I would like to cut the first 213 seconds away from the video
>
> The result is good with really good quality.
>
> However - is there any way to prevent ffmpeg to run thru the entire
> video when doing this? For a TV-show with 2-3 commercial breaks it
> would take a couple of hours to process a 25-minute TV-show.

Try -c:v copy -c:a copy , this avoid re-encode the streams.

>
> And - the command aboce results in a testoutput.m4v-file that
> contains what I would like to cut out. Is there any way that I can
> "reverse" this such that it results in the original video /without/
> the cut-out piece instead? Otherwise I would end up with a number of
> video files that I would need to stitch together again.
>

It seems no way to avoid re-jointing the videos after you cut some
parts if I have not misunderstanded your meaning.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Using ffmpeg to remove commercials from video file

jlundstocholm
Hi,

> Try -c:v copy -c:a copy , this avoid re-encode the streams.

Ok - should I just add those as parameters to the ffmpeg-call? As in:

ffmpeg -ss 213 -c:v copy -c:a copy -i MySourceMovie.m4v testoutput.m4v

The above makes ffmpeg puke on

"unknown decoder 'copy'

ffmpeg -h tells me that the -c option needs a "codec" paramater?

> It seems no way to avoid re-jointing the videos after you cut some
> parts if I have not misunderstanded your meaning.

Ok - this latter part is not a big deal for me since my media center (Plex) supports streaming of split-up files (as far as I remember, at least)

Thanks for you reply :-)

/Jesper
Copenhagen, Denmark
Reply | Threaded
Open this post in threaded view
|

Re: Using ffmpeg to remove commercials from video file

Tom Horsley
In reply to this post by jlundstocholm
On Wed, 14 Aug 2013 01:09:30 -0700 (PDT)
jlundstocholm wrote:

> I am trying to use ffmpeg to remove commercials from films I have recorded on
> my DVR.

Here's a description of the scripts I've been using:

http://home.comcast.net/~tomhorsley/game/ffmpeg.html

I produce several chunks of the video between the
commercials and use the concat filter to stich them
back together.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Using ffmpeg to remove commercials from video file

Paul B Mahol
In reply to this post by jlundstocholm
On 8/14/13, jlundstocholm <[hidden email]> wrote:
> Hi,
>
>> Try -c:v copy -c:a copy , this avoid re-encode the streams.
>
> Ok - should I just add those as parameters to the ffmpeg-call? As in:
>
> ffmpeg -ss 213 -c:v copy -c:a copy -i MySourceMovie.m4v testoutput.m4v
>

It should be:

ffmpeg -ss 213 -i MySourceMovie.m4v -c:v copy -c:a copy testoutput.m4v

> The above makes ffmpeg puke on
>
> "unknown decoder 'copy'
>
> ffmpeg -h tells me that the -c option needs a "codec" paramater?
>
>> It seems no way to avoid re-jointing the videos after you cut some
>> parts if I have not misunderstanded your meaning.
>
> Ok - this latter part is not a big deal for me since my media center (Plex)
> supports streaming of split-up files (as far as I remember, at least)
>
> Thanks for you reply :-)
>
> /Jesper
> Copenhagen, Denmark
>
>
>
> --
> View this message in context:
> http://ffmpeg-users.933282.n4.nabble.com/Using-ffmpeg-to-remove-commercials-from-video-file-tp4660699p4660701.html
> Sent from the FFmpeg-users mailing list archive at Nabble.com.
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Using ffmpeg to remove commercials from video file

jlundstocholm
Hi Paul,

> ffmpeg -ss 213 -i MySourceMovie.m4v -c:v copy -c:a copy testoutput.m4v

This works great and drastically reduces the splitting-time - thank you :-)

For the record - my final script is this - if someone else should need to try the same thing. It took a bit of trial'n error to figure out the correct syntax and usage of the -to switch.

FFMPEG takes less than two minutes to remove commercials from a 2GB movie splitting in 5 files.

ffmpeg -ss "00:00:00" -i "movie.m4v" -to "00:15:18" -c:v copy -c:a copy "result.pt1.m4v"
ffmpeg -ss "00:22:29.500" -i "movie.m4v" -to "00:18:58" -c:v copy -c:a copy "result.pt2.m4v"
ffmpeg -ss "00:50:24.500" -i "movie.m4v" -to "00:16:12" -c:v copy -c:a copy "result.pt3.m4v"
ffmpeg -ss "01:14:48.500" -i "movie.m4v" -to "00:18:44" -c:v copy -c:a copy "result.pt4.m4v"
ffmpeg -ss "01:41:35" -i "movie.m4v" -to "00:18:08" -c:v copy -c:a copy "result.pt5.m4v"

At some point I would like to use a different switch than -to since it takes a duration and not a specific time in the movie - hence forcing me to calculate this duration. But that's for (another) rainy day.

Reply | Threaded
Open this post in threaded view
|

Re: Using ffmpeg to remove commercials from video file

Werner Robitza
> For the record - my final script is this - if someone else should need to
> try the same thing. It took a bit of trial'n error to figure out the
> correct
> syntax and usage of the -to switch.
>

Where is your script?


> At some point I would like to use a different switch than -to since it
> takes
> a /duration/ and not a specific time in the movie - hence forcing me to
> calculate this duration. But that's for (another) rainy day.
>

-to does not take a duration – it takes the timestamp of where you would
like
encoding to end. This is exactly the option you need.

-t takes the encoding duration. Depending on your programming/scripting
language of choice it's rather easy to calculate the difference between two
HH:MM:SS.mmmm timestamps.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Using ffmpeg to remove commercials from video file

jlundstocholm
Hi Werner,

Thanks for your reply.

> Where is your script?

My bad - I meant "configuration of ffmpeg" - for now I'm doing it by hand.

> -to does not take a duration – it takes the timestamp of where you would
> like encoding to end. This is exactly the option you need.

Yes, the manual tells me:

-to time_stop       record or transcode stop time

But can you explain to me why the to-switches I applied to ffmpeg behaves like a duration? ffmpeg produces 5 files to me - with the lengths

00:15:18
00:18:58
00:16:12
00:18:44
00:18:08

It sure behaves like a duration, but of course I might be using ffmpeg wrongly ... it is certainly an option.

Thanks,

/Jesper
Copenhagen, Denmark
Reply | Threaded
Open this post in threaded view
|

Re: Using ffmpeg to remove commercials from video file

Werner Robitza
On Mon, Aug 19, 2013 at 8:26 PM, jlundstocholm <[hidden email]> wrote:
>
> But can you explain to me why the to-switches I applied to ffmpeg behaves
> like a duration? ffmpeg produces 5 files to me - with the lengths
>
> 00:15:18
> 00:18:58
> 00:16:12
> 00:18:44
> 00:18:08

Maybe I'm missing context here, but what exact ffmpeg calls are you
using that produce said files?

As far as I know the -to option works exactly as intended.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Using ffmpeg to remove commercials from video file

jlundstocholm
Hi Werner,

> Maybe I'm missing context here, but what exact ffmpeg calls are you
> using that produce said files?

ffmpeg -ss "00:00:00" -i "movie.m4v" -to "00:15:18" -c:v copy -c:a copy "result.pt1.m4v"
ffmpeg -ss "00:22:29.500" -i "movie.m4v" -to "00:18:58" -c:v copy -c:a copy "result.pt2.m4v"
ffmpeg -ss "00:50:24.500" -i "movie.m4v" -to "00:16:12" -c:v copy -c:a copy "result.pt3.m4v"
ffmpeg -ss "01:14:48.500" -i "movie.m4v" -to "00:18:44" -c:v copy -c:a copy "result.pt4.m4v"
ffmpeg -ss "01:41:35" -i "movie.m4v" -to "00:18:08" -c:v copy -c:a copy "result.pt5.m4v"
Reply | Threaded
Open this post in threaded view
|

Re: Using ffmpeg to remove commercials from video file

Werner Robitza
On Mon, Aug 19, 2013 at 10:15 PM, jlundstocholm
<[hidden email]> wrote:

>
>> Maybe I'm missing context here, but what exact ffmpeg calls are you
>> using that produce said files?
>
>
>
>
>
> --
> View this message in context: http://ffmpeg-users.933282.n4.nabble.com/Using-ffmpeg-to-remove-commercials-from-video-file-tp4660699p4660786.html

Now I know what's going on. Your message turns up empty here. This
would explain why I didn't see your script earlier – it was swallowed
somewhere in the mail chain.
Please disable rich text formatting in your mail client and send as
plain-text only.

Ideally, can you show us the full, uncut console output for a command
where you think the -to option is not working properly?

Thanks!
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Using ffmpeg to remove commercials from video file

jlundstocholm
Hi Werner,

> Now I know what's going on. Your message turns up empty here. This
> would explain why I didn't see your script earlier – it was swallowed
> somewhere in the mail chain.
> Please disable rich text formatting in your mail client and send as
> plain-text only.

Well, I was actually using the web-ui on nabble.com - I assumed it would "do the right thing" in terms of creating both a "rich" version of the post and a plain-text version as well. I'll switch to regular mail instead when I have produced the output you are asking for.

:o)

/Jesper
Copenhagen, Denmark
Reply | Threaded
Open this post in threaded view
|

Re: Using ffmpeg to remove commercials from video file

Jesper Lund Stocholm
Hi Werner,



> > Now I know what's going on. Your message turns up empty here. This
> > would explain why I didn't see your script earlier – it was swallowed
> > somewhere in the mail chain.
> > Please disable rich text formatting in your mail client and send as
> > plain-text only.
>
>
So the commands I use are these:

ffmpeg -ss "00:00:00.000" -i "movie.m4v" -to "00:15:18" -c:v copy -c:a copy
"result.pt1.m4v"
ffmpeg -ss "00:22:29.500" -i "movie.m4v" -to "00:18:58" -c:v copy -c:a copy
"result.pt2.m4v"
ffmpeg -ss "00:50:24.500" -i "movie.m4v" -to "00:16:12" -c:v copy -c:a copy
"result.pt3.m4v"
ffmpeg -ss "01:14:48.500" -i "movie.m4v" -to "00:18:44" -c:v copy -c:a copy
"result.pt4.m4v"
ffmpeg -ss "01:41:35.000" -i "movie.m4v" -to "00:18:08" -c:v copy -c:a copy
"result.pt5.m4v"


Complete console output for the second command (file two) is this:

c:\users\jst\desktop\ffmpeg -ss "00:22:29.500" -i "movie.m4v" -to
"00:18:58" -c:v copy -c:a copy "c:\users\jst\desktop\output.pt2.m4v"
ffmpeg version N-55393-g3b2e99f Copyright (c) 2000-2013 the FFmpeg
developers
  built on Aug  8 2013 21:37:55 with gcc 4.7.3 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads
--enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls
--enab
le-iconv --enable-libass --enable-libbluray --enable-libcaca
--enable-libfreetyp
e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame
--ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg
--enable-l
ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr
--enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc
--enable-libvo-
amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264
--enable-libxavs --
enable-libxvid --enable-zlib
  libavutil      52. 41.100 / 52. 41.100
  libavcodec     55. 24.100 / 55. 24.100
  libavformat    55. 13.102 / 55. 13.102
  libavdevice    55.  3.100 / 55.  3.100
  libavfilter     3. 82.100 /  3. 82.100
  libswscale      2.  4.100 /  2.  4.100
  libswresample   0. 17.103 /  0. 17.103
  libpostproc    52.  3.100 / 52.  3.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 00000000002ea860] stream 0, timescale not set
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'movie.m4v':
  Metadata:
    major_brand     : M4VH
    minor_version   : 1
    compatible_brands: M4VHM4A mp42isom
    creation_time   : 2012-11-18 22:23:57
    title           : Prinsessen og Fr├©en
    description     : 2009, Animation - (The Princess and the Frog)
Amerikansk a
nimationsfilm fra 2009. Den smukke prinsesse Tiana m├©der en fr├©, som i
virkeli
gheden er en prins, der er desperat for at blive forvandlet til et menneske
igen
. Et sk├ªbnesvangert kys tryller ogs├
    synopsis        : 2009, Animation - (The Princess and the Frog)
Amerikansk a
nimationsfilm fra 2009. Den smukke prinsesse Tiana m├©der en fr├©, som i
virkeli
gheden er en prins, der er desperat for at blive forvandlet til et menneske
igen
. Et sk├ªbnesvangert kys tryller ogs├
    comment         : 2009, Animation - (The Princess and the Frog)
Amerikansk a
nimationsfilm fra 2009. Den smukke prinsesse Tiana m├©der en fr├©, som i
virkeli
gheden er en prins, der er desperat for at blive forvandlet til et menneske
igen
. Et sk├ªbnesvangert kys tryller ogs├
    media_type      : 0
    network         : Kanal 5 DK
    genre           : TV Shows
    date            : 2009-01-01
  Duration: 02:01:39.36, start: 0.000000, bitrate: 5089 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p,
1280x720,
 4953 kb/s, 25 fps, 25 tbr, 2500 tbn, 5k tbc
    Metadata:
      creation_time   : 2012-11-18 22:23:58
      handler_name    : Apple Video Media Handler
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo,
fltp, 12
5 kb/s
    Metadata:
      creation_time   : 2012-11-18 22:24:00
      handler_name    : Apple Sound Media Handler
    Stream #0:2: Video: mjpeg, yuvj420p, 512x748 [SAR 1:1 DAR 128:187], 90k
tbr,
 90k tbn, 90k tbc
Output #0, ipod, to 'c:\users\jst\desktop\movie.pt2.m
4v':
  Metadata:
    major_brand     : M4VH
    minor_version   : 1
    compatible_brands: M4VHM4A mp42isom
    date            : 2009-01-01
    title           : Prinsessen og Fr├©en
    description     : 2009, Animation - (The Princess and the Frog)
Amerikansk a
nimationsfilm fra 2009. Den smukke prinsesse Tiana m├©der en fr├©, som i
virkeli
gheden er en prins, der er desperat for at blive forvandlet til et menneske
igen
. Et sk├ªbnesvangert kys tryller ogs├
    synopsis        : 2009, Animation - (The Princess and the Frog)
Amerikansk a
nimationsfilm fra 2009. Den smukke prinsesse Tiana m├©der en fr├©, som i
virkeli
gheden er en prins, der er desperat for at blive forvandlet til et menneske
igen
. Et sk├ªbnesvangert kys tryller ogs├
    comment         : 2009, Animation - (The Princess and the Frog)
Amerikansk a
nimationsfilm fra 2009. Den smukke prinsesse Tiana m├©der en fr├©, som i
virkeli
gheden er en prins, der er desperat for at blive forvandlet til et menneske
igen
. Et sk├ªbnesvangert kys tryller ogs├
    media_type      : 0
    network         : Kanal 5 DK
    genre           : TV Shows
    encoder         : Lavf55.13.102
    Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), yuv420p, 1280x720,
q=2-31
, 4953 kb/s, 25 fps, 10k tbn, 2500 tbc
    Metadata:
      creation_time   : 2012-11-18 22:23:58
      handler_name    : Apple Video Media Handler
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, 125
kb/s

    Metadata:
      creation_time   : 2012-11-18 22:24:00
      handler_name    : Apple Sound Media Handler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 5403 fps=0.0 q=-1.0 size=  137903kB time=00:03:36.70
bitrate=5213.0kbits/
frame=11494 fps=11493 q=-1.0 size=  285293kB time=00:07:40.42
bitrate=5076.1kbit
frame=17750 fps=11833 q=-1.0 size=  415500kB time=00:11:50.78
bitrate=4788.7kbit
frame=23625 fps=11529 q=-1.0 size=  551621kB time=00:15:45.79
bitrate=4777.9kbit
frame=28452 fps=11201 q=-1.0 Lsize=  702461kB time=00:18:58.00
bitrate=5056.7kbi
ts/s
video:684096kB audio:17515kB subtitle:0 global headers:0kB muxing overhead
0.121
056%


 (also attached as unicode text file)



Thank you so much for your input on this

--
Jesper Lund Stocholm
www.idippedut.dk
SC34/WG4 http://www.itscj.ipsj.or.jp/sc34/wg4/

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

output.txt (14K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Using ffmpeg to remove commercials from video file

Werner Robitza
On Tue, Aug 20, 2013 at 9:54 AM, Jesper Lund Stocholm
<[hidden email]> wrote:

> So the commands I use are these:
>
> ffmpeg -ss "00:00:00.000" -i "movie.m4v" -to "00:15:18" -c:v copy -c:a copy
> "result.pt1.m4v"
> ffmpeg -ss "00:22:29.500" -i "movie.m4v" -to "00:18:58" -c:v copy -c:a copy
> "result.pt2.m4v"
> ffmpeg -ss "00:50:24.500" -i "movie.m4v" -to "00:16:12" -c:v copy -c:a copy
> "result.pt3.m4v"
> ffmpeg -ss "01:14:48.500" -i "movie.m4v" -to "00:18:44" -c:v copy -c:a copy
> "result.pt4.m4v"
> ffmpeg -ss "01:41:35.000" -i "movie.m4v" -to "00:18:08" -c:v copy -c:a copy
> "result.pt5.m4v"

I see now.

Note that -ss specifies the start time and -to the end time.
You cannot start at 22:29 and end at 18:58. Unless you expect ffmpeg
to travel back in time :)

If you want it to start at 22:29 and encode for 18 minutes and 58
seconds, you need -t, not -to.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Using ffmpeg to remove commercials from video file

Jesper Lund Stocholm
Hi Werner,


2013/8/20 Werner Robitza <[hidden email]>

>
>
> Note that -ss specifies the start time and -to the end time.
> You cannot start at 22:29 and end at 18:58. Unless you expect ffmpeg
> to travel back in time :)
>
> If you want it to start at 22:29 and encode for 18 minutes and 58
> seconds, you need -t, not -to.
>
>
Yes, I would think that as well. The thing is just that if I use the
timestamp instead of the duration, e.g.


ffmpeg -ss "00:22:29.500" -i "movie.m4v" -to "00:41:27" -c:v copy -c:a copy
"output.pt2_to_4127.m4v"
ffmpeg -ss "00:22:29.500" -i "movie.m4v" -t "00:41:27" -c:v copy -c:a copy
"output.pt2_t_4127.m4v"

ffmpeg produces exactly identical files and console output (apart from the
actual copying of stream that vary a little bit (I assume that is because
of my machine doing other stuff as well)).

Both files are 41:27 minutes in length.


--
Jesper Lund Stocholm
www.idippedut.dk
SC34/WG4 http://www.itscj.ipsj.or.jp/sc34/wg4/

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

output_t_4127.txt (21K) Download Attachment
output_to_4127.txt (22K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Using ffmpeg to remove commercials from video file

Werner Robitza
On Tue, Aug 20, 2013 at 12:13 PM, Jesper Lund Stocholm
<[hidden email]> wrote:
> ffmpeg produces exactly identical files and console output (apart from the
> actual copying of stream that vary a little bit (I assume that is because
> of my machine doing other stuff as well)).
>
> Both files are 41:27 minutes in length.

I reproduced this now.

Here's the problem: When you use -ss before the input file, it skips
to the specified point, and then assumes this as being position
00:00:00 (i.e., the start of the file).
So, these are the same, because for ffmpeg the file starts at 0:

ffmpeg -ss 00:01:00 -i input -t 00:02:00 output
ffmpeg -ss 00:01:00 -i input -to 00:02:00 output

This however works and creates a file with 2 min length and 1 min
length, respectively:

ffmpeg -i input -ss 00:01:00 -t 00:02:00 output
ffmpeg -i input -ss 00:01:00 -to 00:02:00 output

Hope you understand what I mean.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user