VideoHelp Forum
+ Reply to Thread
Results 1 to 8 of 8
Thread
  1. Member
    Join Date
    Jul 2008
    Location
    United States
    Search Comp PM
    Hi --

    I'm capturing from a Hauppauge USB-Live2 capture card on kubuntu 24.10. ffmpeg command looks like this:

    ffmpeg -f alsa -ac 2 -i hw:CARD=Cx231xxAudio,DEV=0 -f v4l2 -i /dev/video2 -c:a copy -c:v rawvideo test.avi
    ...when I try to play test.avi in vlc, the video looks fine but the audio is broken into bits and dragged longer than it should be. In other words, what should be
    Code:
    123456
    is actually played in pieces as
    Code:
        1   2   3   4   5   6
    If I play VLC to play it, the video is fine but the audio skips. If I use ffplay to play it, the audio plays fine, but the video is sped up way too fast. Smells like pts issues?

    If I demux the video and audio using ffmpeg, the individual files play fine. This tells me that there is some kind of timing data being stored in the file that is incorrect. If I do this:

    Code:
    ffmpeg -i test.avi -c:a copy -c:v copy test-remuxed.avi
    ...the resulting files are identical when checked with ffprobe, but the "remuxed" version plays fine. If I extract the pts values like this:

    Code:
    ffmpeg -i test.avi -vf showinfo -af ashowinfo -fps_mode passthrough -copyts -f null /dev/null 2> pts.txt
    ...and I compared the broken original with the "remuxed" version, the pts for the video frames are the same in both versions, but the audio chunk pts are different. In the original, when ashowinfo reports x samples, it adds 4x to the pts; if you see here, nb_samples is 1024 but it jumps to pts:4096, then nb_samples is 256 and it jumps to pts:5120

    [Parsed_ashowinfo_0 @ 0x70654c002f80] n:0 pts:0 pts_time:0 fmt:s16 channels:2 chlayout:stereo rate:48000 nb_samples:1024 checksum:73F22CAC plane_checksums: [ 73F22CAC ]
    [Parsed_ashowinfo_0 @ 0x70654c002f80] n:1 pts:4096 pts_time:0.0853333 fmt:s16 channels:2 chlayout:stereo rate:48000 nb_samples:256 checksum:929680FC plane_checksums: [ 929680FC ]
    [Parsed_ashowinfo_0 @ 0x70654c002f80] n:2 pts:5120 pts_time:0.106667 fmt:s16 channels:2 chlayout:stereo rate:48000 nb_samples:1024 checksum:7A55BBD5 plane_checksums: [ 7A55BBD5 ]
    In the working "remuxed" version the pts are linear with respect to the nb_samples:

    [Parsed_ashowinfo_0 @ 0x76a788002f80] n:0 pts:0 pts_time:0 fmt:s16 channels:2 chlayout:stereo rate:48000 nb_samples:1024 checksum:73F22CAC plane_checksums: [ 73F22CAC ]
    [Parsed_ashowinfo_0 @ 0x76a788002f80] n:1 pts:1024 pts_time:0.0213333 fmt:s16 channels:2 chlayout:stereo rate:48000 nb_samples:256 checksum:929680FC plane_checksums: [ 929680FC ]
    [Parsed_ashowinfo_0 @ 0x76a788002f80] n:2 pts:1280 pts_time:0.0266667 fmt:s16 channels:2 chlayout:stereo rate:48000 nb_samples:1024 checksum:7A55BBD5 plane_checksums: [ 7A55BBD5 ]
    One other clue that may be important: when capturing, I get numerous errors like:

    [vost#0:0/rawvideo @ 0x55f451f6b280] Clipping frame in rate conversion by 0.011955
    and:

    [aost#0:1/copy @ 0x55f451f75440] Non-monotonic DTS; previous: 29662, current: 29564; changing to 29663. This may result in incorrect timestamps in the output file.
    Any idea what's going on? Thanks!
    Quote Quote  
  2. Member
    Join Date
    Feb 2006
    Location
    United States
    Search Comp PM
    Originally Posted by chconnor View Post
    Hi --

    I'm capturing from a Hauppauge USB-Live2 capture card on kubuntu 24.10. ffmpeg command looks like this:

    ffmpeg -f alsa -ac 2 -i hw:CARD=Cx231xxAudio,DEV=0 -f v4l2 -i /dev/video2 -c:a copy -c:v rawvideo test.avi
    ...when I try to play test.avi in vlc, the video looks fine but the audio is broken into bits and dragged longer than it should be. In other words, what should be
    Code:
    123456
    is actually played in pieces as
    Code:
        1   2   3   4   5   6
    If I play VLC to play it, the video is fine but the audio skips. If I use ffplay to play it, the audio plays fine, but the video is sped up way too fast. Smells like pts issues?

    If I demux the video and audio using ffmpeg, the individual files play fine. This tells me that there is some kind of timing data being stored in the file that is incorrect. If I do this:

    Code:
    ffmpeg -i test.avi -c:a copy -c:v copy test-remuxed.avi
    ...the resulting files are identical when checked with ffprobe, but the "remuxed" version plays fine. If I extract the pts values like this:

    Code:
    ffmpeg -i test.avi -vf showinfo -af ashowinfo -fps_mode passthrough -copyts -f null /dev/null 2> pts.txt
    ...and I compared the broken original with the "remuxed" version, the pts for the video frames are the same in both versions, but the audio chunk pts are different. In the original, when ashowinfo reports x samples, it adds 4x to the pts; if you see here, nb_samples is 1024 but it jumps to pts:4096, then nb_samples is 256 and it jumps to pts:5120

    [Parsed_ashowinfo_0 @ 0x70654c002f80] n:0 pts:0 pts_time:0 fmt16 channels:2 chlayouttereo rate:48000 nb_samples:1024 checksum:73F22CAC plane_checksums: [ 73F22CAC ]
    [Parsed_ashowinfo_0 @ 0x70654c002f80] n:1 pts:4096 pts_time:0.0853333 fmt16 channels:2 chlayouttereo rate:48000 nb_samples:256 checksum:929680FC plane_checksums: [ 929680FC ]
    [Parsed_ashowinfo_0 @ 0x70654c002f80] n:2 pts:5120 pts_time:0.106667 fmt16 channels:2 chlayouttereo rate:48000 nb_samples:1024 checksum:7A55BBD5 plane_checksums: [ 7A55BBD5 ]
    In the working "remuxed" version the pts are linear with respect to the nb_samples:

    [Parsed_ashowinfo_0 @ 0x76a788002f80] n:0 pts:0 pts_time:0 fmt16 channels:2 chlayouttereo rate:48000 nb_samples:1024 checksum:73F22CAC plane_checksums: [ 73F22CAC ]
    [Parsed_ashowinfo_0 @ 0x76a788002f80] n:1 pts:1024 pts_time:0.0213333 fmt16 channels:2 chlayouttereo rate:48000 nb_samples:256 checksum:929680FC plane_checksums: [ 929680FC ]
    [Parsed_ashowinfo_0 @ 0x76a788002f80] n:2 pts:1280 pts_time:0.0266667 fmt16 channels:2 chlayouttereo rate:48000 nb_samples:1024 checksum:7A55BBD5 plane_checksums: [ 7A55BBD5 ]
    One other clue that may be important: when capturing, I get numerous errors like:

    [vost#0:0/rawvideo @ 0x55f451f6b280] Clipping frame in rate conversion by 0.011955
    and:

    [aost#0:1/copy @ 0x55f451f75440] Non-monotonic DTS; previous: 29662, current: 29564; changing to 29663. This may result in incorrect timestamps in the output file.
    Any idea what's going on? Thanks!
    try adding -reset_timestamps to your command and see how that works out.
    Quote Quote  
  3. Member
    Join Date
    Jul 2008
    Location
    United States
    Search Comp PM
    Thanks! I'll give it a shot tomorrow.

    All the documentation i find for reset_timestamps seems to imply that it's for the system stream segmenter muxer - am i somehow using that in the background of this process?
    Last edited by chconnor; 17th Nov 2024 at 18:12.
    Quote Quote  
  4. Member
    Join Date
    Jul 2008
    Location
    United States
    Search Comp PM
    Tried it -- couldn't get the command to work. Am I missing something?

    If I insert it before the audio stream spec (-i) I get:

    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 720x480, 165722 kb/s, 29.97 fps, 29.97 tbr, 1000k tbn
    Output #0, alsa, to 'hw:CARD=Cx231xxAudio,DEV=0':
    [out#0/alsa @ 0x647afc8110c0] Output file does not contain any stream
    Error opening output file hw:CARD=Cx231xxAudio,DEV=0.
    Error opening output files: Invalid argument
    [video4linux2,v4l2 @ 0x647afc80ec80] Some buffers are still owned by the caller on close.
    ioctl(VIDIOC_QBUF): Bad file descriptor

    If I insert it before the video stream:

    Output #0, video4linux2,v4l2, to '/dev/video2':
    [out#0/video4linux2,v4l2 @ 0x5ff5a1379340] Output file does not contain any stream
    Error opening output file /dev/video2.
    Error opening output files: Invalid argument

    If before the output filename it just doesn't see the output filename and gives a warning "Trailing option(s) found in the command: may be ignored."

    I tried a variety of locations and couldn't get it to work... any other thoughts?
    Quote Quote  
  5. Member
    Join Date
    Feb 2006
    Location
    United States
    Search Comp PM
    Originally Posted by chconnor View Post
    Tried it -- couldn't get the command to work. Am I missing something?

    If I insert it before the audio stream spec (-i) I get:

    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 720x480, 165722 kb/s, 29.97 fps, 29.97 tbr, 1000k tbn
    Output #0, alsa, to 'hw:CARD=Cx231xxAudio,DEV=0':
    [out#0/alsa @ 0x647afc8110c0] Output file does not contain any stream
    Error opening output file hw:CARD=Cx231xxAudio,DEV=0.
    Error opening output files: Invalid argument
    [video4linux2,v4l2 @ 0x647afc80ec80] Some buffers are still owned by the caller on close.
    ioctl(VIDIOC_QBUF): Bad file descriptor

    If I insert it before the video stream:

    Output #0, video4linux2,v4l2, to '/dev/video2':
    [out#0/video4linux2,v4l2 @ 0x5ff5a1379340] Output file does not contain any stream
    Error opening output file /dev/video2.
    Error opening output files: Invalid argument

    If before the output filename it just doesn't see the output filename and gives a warning "Trailing option(s) found in the command: may be ignored."

    I tried a variety of locations and couldn't get it to work... any other thoughts?
    try adding a 1 after reset_timestamps (-reset_timestamps 1) see if that works.

    or try adding -fflags +genpts to your command This flag tells FFmpeg to generate PTS values based on the input stream’s timestamps, ensuring consistent and monotonically increasing values. Google ffmpeg -pts issue for more info
    Last edited by october262; 17th Nov 2024 at 19:48.
    Quote Quote  
  6. Member
    Join Date
    Jul 2008
    Location
    United States
    Search Comp PM
    Argh, sorry for being dense! I put -reset_timestamps 1 just before the output filename (other locations it said "unknown option") -- no change in results, unfortunately.

    Also tried --fflags +genpts -- no change in results.

    I googled ffmpeg -pts issue but didn't find anything obvious that you might have been referring to... ?

    (I also tried various versions of -bsf:a setts=... but I don't really know what I'm doing and wasn't able to make anything good happen.)
    Quote Quote  
  7. Member
    Join Date
    Jul 2008
    Location
    United States
    Search Comp PM
    Progress: I discovered that if I specify the sample rate and format, even though I am specifying exactly what the stream already is detected to be, the result works and the pts values increment as expected:

    ffmpeg -f alsa -ac 2 -i hw:CARD=Cx231xxAudio,DEV=0 -f v4l2 -i /dev/video2 -c:a pcm_s16le -ar 48000 -c:v rawvideo test.avi

    Not sure if this is a bug?
    Quote Quote  
  8. Member
    Join Date
    Jul 2008
    Location
    United States
    Search Comp PM
    Suspected bug in ffmpeg; see here for more: https://trac.ffmpeg.org/ticket/11314
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!