mlv_dump -f... give one more frame than expected

Issue #2560 resolved
escho created an issue

mlv_dump -f 1 give 2 frames mlv_dump -f 2 give 3 frames and so on

mlv_dump -f 1-2 is correct (2 frames)

happens on both, MLV-output and dngs

compiled today from actual sources

Comments (12)

  1. Daniel Fort

    I came across this issue today. What I was trying to do is to pull out just the first frame.

    -f 0 should extract the first frame (000000) but it extracts all the frames. -f 1 extracts the first 2 frames (000000 and 000001). I wouldn't say that it gives one more frame than expected as long as you take into account that the first frame is numbered 0.

    If you give a range the results are different. -f 1-1 will extract only 1 frame (000001) but -f 0-0 will once again extract all the frames.

    Seems there is no way to get just that first frame by itself.

    The issue seems to be here:

                case 'f':
                    {
                        char *dash = strchr(optarg, '-');
    
                        /* try to parse "1-10" */
                        if(dash)
                        {
                            *dash = '\000';
                            frame_start = atoi(optarg);
                            frame_end = atoi(&dash[1]);
    
                            /* to makse sure it is a valid range */
                            if(frame_start > frame_end)
                            {
                                frame_end = frame_start;
                            }
                        }
                        else
                        {
                            /* only the frame end is specified */
                            frame_end = MAX(0, atoi(optarg));
                        }
                    }
                    break;
    
  2. DeafEyeJedi

    I can confirm this as well. First DNG of each MLV seems broken with latest mlv_dump after shooting 10/12-bit files. I still need to shoot more tests to narrow down the possibilities of why this is happening ... has to be a simple fix somewhere to get rid of this culprit!

  3. Daniel Fort

    Ok, say you want to extract just the first frame from a batch of MLV files to see if they are corrupted. The first frame is numbered 0 but if the frame_end is also 0 then frame_selected is false and the block of code to extract x number of frames is skipped:

    /* when no end was specified, save all frames */
    uint32_t frame_selected = (!frame_end) || ((block_hdr.frameNumber >= frame_start) && (block_hdr.frameNumber <= frame_end));
    
    if(frame_selected)
    
  4. escho reporter

    compiled just a moment ago

    output mlv_dump:

     -f frames           frames to save. e.g. '12' saves the first 12 frames, '12-40' saves frames 12 to 40.
    

    but mlv_dump -f 12 doesn´t save 12 frames, it saves 13 frames ( frame 0 - frame 12).

    So the issue isn´t solved

  5. Daniel Fort

    Check out the revised instructions:

    https://www.magiclantern.fm/forum/index.php?topic=7122.0

    # will dump frames 0 through 123 into a new file
    # note that ./mlv_dump --dng -f 0 in.mlv (or ./mlv_dump --dng -f 0-0 in.mlv) will now extract just frame 0 instead of all of the frames.
    ./mlv_dump -f 123 -o out.mlv in.mlv
    

    The issue is that the first frame is numbered 0 so there will always be one more frame than the end frame indicates--right? The only way to "fix" that is to have the first frame start at 1 but that's not the way image sequences are usually numbered.

  6. escho reporter

    Thanks for the link

    Please change this in mlv_dump.c too, to avoid confusion.

    void show_usage(char *executable)
    ...
        **print_msg(MSG_INFO, " -f frames           frames to save. e.g. '12' saves the first 12 frames, '12-40' saves frames 12 to 40.\n");**
    
  7. Daniel Fort

    Good catch. I'll get to it as soon as I can--or you can fix it if you want practice with making a pull request. This would be a good one to get started.

  8. escho reporter

    Yes, I´ll create a pull request. But I need some time, before I can do it ( two or three weeks, I guess)

  9. Daniel Fort

    Should only take two or three minutes. In any case, this will be a good one to start with so I'll leave it to you. You might want to assign this issue to yourself so the developers know you're working on it.

  10. Log in to comment